How do I get the current drive letter in WIndows 7 CMD? - system

In Windows 7 the DOS variable %cd% returns the current drive. However when BAT file is started with admin rights (Run as administrator), then %cd% returns "C:\Windows\System32" instead of the current drive. Please, help.

%CD:~0,3% should give just the first three characters (C:)...

Related

Setting default windows terminal starting directory to folder within c drive WSL

I am trying to set my default terminal for my WSL prompt in windows terminal to start at a specific folder under the C drive.
i am able to set the default to /mnt but it wont let me go /mnt/c/<myfolder> whenever i do this is sets it back to /mnt/c/Users/<myuser>
In settings.json if you are using the commandline property replace that line with:
"source": "Windows.Terminal.Wsl"
Then set the value of your startingDirectory to where ever you like in the C drive using the drive letter and forward slashes in the path, so it will look something like this:
"startingDirectory" : "C:/Windows/Fonts",

Script to delete all photoshop temp files older than 2 days

I have this commen issue with photoshop. Where it doesn't delete the temp files it creates after a shutdown of program.
I have used alot of time to find a script that would delete all files with starting name of Photoshop* in the temp, which is older than 2 days. So i dont delete files, if i get a unexpected shutdown or crash.
I tried this, after a few hours of search - but it doenst work
ForFiles /p "C:\Users\user\AppData\Local\Temp\Photo*" /s /d -2 /c "cmd /c del #file"
This works, perfectly but it deletes all files without taking into consideration how old the files are.
C:\
del "C:\Users\user\AppData\Local\Temp\Photoshop*."
How can i get the above script, which runs on every startup with system rights.
To only delete all files starting with photoshop* and are older than 2 days :)
I need this script to work on Windows10 and Windows7
Every input is appreciated.

Robocopy fails with security error copying "from nas to nas". Why?

tl;dr
robocopy has security problems copying from 'nas to nas'
The system detected a possible attempt to compromise security. Please
ensure that you can contact the server that authenticated you.
Summary
I'm running into "windows permission problems" when making backups using using the following:
powershell
robocopy
Windows 2008R2
Windows task scheduler
Task Scheduler output
Taskscheduler runs under user domain account "OPS\backupuser"
The script succeeds when it copies "from local drive" "to the backup nas"
However it fails when the script copies "from another nas" "to the backup nas"
In pictures...
Success: local drive --copy-to--> backup NAS
Fails: another NAS --copy-to--> backup NAS
Output
Robocopy fails with exit code 16.
Here is detailed output:
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Thu Jul 07 22:22:11 2016
2016/07/07 22:22:26 ERROR 1265 (0x000004F1) Getting File System Type of Source \\app-data-nas.hosting.acme\bazapp$\production\foo_industries_prod\
The system detected a possible attempt to compromise security. Please ensure that you can contact the server that authenticated you.
Source - \\app-data-nas.hosting.acme\bazapp$\production\foo_industries_prod\
Dest : \\dr-backup-nas\AppDR$\ALL_DR\FOO_INDUSTRIES_DR\foo_industries_prod\
Files : *.*
Options : *.* /NDL /S /E /COPY:DT /PURGE /MIR /B /NP /R:0 /W:1
------------------------------------------------------------------------------
Other points
1) Because I the environment is 'locked down', I could not run this from the command line, either as :
my own account
my own account with elevated command prompt
OPS\backupuser
2) I tried adding '/NODCOPY' , but robocopy failed; apparently we don't have the hotfix for this option.
Thanks in advance!
NAS drives are not Windows drives. You have to map to them uniquely and with certain admin privileges to make them "see" you're trying to copy stuff into them.
First map a drive to the NAS system using NET USE
Next copy the file(s) using ROBOCOPY thus...
robocopy <source path> <nas path> <file(s)> /s /j /r:2 /w:5 /log+:robocopy.log
Place it all inside a CMD file and run it from a Task Scheduler on your Windows server.
>
>
>NAS drives are not Windows drives. You have to map to them uniquely and with certain >admin privileges to make them "see" you're trying to copy stuff into them.>
>
>First map a drive to the NAS system using NET USE
>
>Next copy the file(s) using ROBOCOPY thus...
>
>robocopy <source path> <nas path> <file(s)> /s /j /r:2 /w:5 /log+:robocopy.log
>Place it all inside a CMD file and run it from a Task Scheduler on your Windows server.
>
You forgot:
/FFT #":: assume FAT File Times (2-second granularity)" -ensures the copy ignores OS file system while copying in ROBOCOPY
/Z #":: Includes LARGE file copy restart" - restarts large file copying where the copy left off in the file, instead of starting over again. Like in a 500 GB file it restarts at the byte the copy stopped at, in case you need to schedule offline copying and don't want large files to prevent the copy progression (will ONLY start over if the file date changed!)
/xo #"exclude older files" -copies all new files - something useful to retry copies in Scheduled task Job of Robocopy...
All these are useful in NAS copying... as they tend to have issues resolved by these switches in ROBOCOPY.

How do you handle "File Access Denied" when deleting a file with the FileInfo.Delete method in VB

I am deleting log files >= 2 days old on a server with the following code:
'Iterate through all files in specified path
For Each file As IO.FileInfo In New IO.DirectoryInfo(sDirPath).GetFiles(sFileType)
'Delete all log files 2 days old or older
If (Now - file.CreationTime).Days >= iNumDays Then
file.Delete()
End If
Next
This code works find on a regular windows machine. On the server, it is setup to query the user for Administrative permissions and click continue to delete the file. I have admin rights on the server. My question is, how do you "click Continue" in code when the file.Delete method is executed?
Hope these are useful:
Create elevated Shortcut to run Program bypassing UAC Prompt in
Windows 8 |
7
Deactivate UAC in Windows 7 for a specific
program

PSExec: How can I show a JPG file on a remote computer?

I need to start a document on a remote computer instead of an executable file, using PSExec.
I tried to provide the file name of a jpg file to psexec associated with the -c command to copy the file, but the message returned for documents (and not executables) is always "The system cannot find the file specified."
Anyone any ideas what the command-line for psexec should be?
Try to use the command:
cmd.exe /c START c:\path\to\document.jpg
Document must be on the remote computer, so you have to copy it there by other command before calling psexec.
Pick a program on that other machine that can show the JPEG and execute that, passing to it the path and name to the file you want to show.
As you've noticed, file associations doesn't work with remote execution like that, so you need to invoke the correct program instead.
In order to open a remote program and not only activate its process you have to use PSEXEC
with the -i (Interactive Mode) and MUST define the session number.
For example:
Usually on a Win7 host:
Console = Session 0
System = Session 1
User = Session 2
In order to activate and open notepad.exe on this remote Win 7 host use the following syntax:
psexec -i 2 \\ComputerName -u User -p Pass notepad.exe
Regards,
Shai Ziv
shaix.ziv#intel.com
This is the way that worked for me:
I've logged on to the via RDP:
I've copied a picture to the to "C:\Users<MyUserName>\Pictures\smiley.png"
I've opened a new powershell-window, typed "tasklist" and found out my windows session id (I simple took the highest session id I've found)
Back on my own PC:
I've downloaded PSTOOLS from https://download.sysinternals.com/files/PSTools.zip
I've unpacked PSTOOLS and placed it in "C:\Program Files\PSTools"
I've opened a new powershell-window and typed: cd "C:\Program Files\PSTools"
Finally i've started the remote PAINT with:
"C:\Program Files\PSTools\psexec" -s -i 4 "\\[RemoteComputerName]" "C:\Windows\system32\mspaint.exe" "C:\Users\[MyUserName]\Pictures\smiley.png"
P.S.: Don't forget to replace [RemoteComputerName] and [MyUserName]