Reputation: 401
I'm trying to move sleep.exe and nircmd.exe to C:\Windows using move command in my batch file. The code goes like this
move "%cd%\sleep.exe" "C:\Windows"
move "%cd%\nircmd.exe" "C:\Windows"
When I do not use administrator privileges I get error:
Access denied
But when I use administrator privileges I get error:
System cannot find the path specified
EDIT: I also tried:
move "%cd%\sleep.exe" "C:\users\%username%\desktop"
And that worked, but as I said I want it to move to C:\Windows
Upvotes: 0
Views: 215
Reputation: 401
I didn't know that administrator mode changes your current director (%cd%) but thanks to @foxidrive i know that now gooled it and found the answer
@setlocal enableextensions
@cd /d "%~dp0"
Upvotes: 1
Reputation: 41224
When using administrator it resets the working directory, and which is why it couldn't find the files.
The solution here sets the location of the files to the folder which contains the batch file.
for %%a in ("sleep.exe" "nircmd.exe") do move "%~dp0\%%~a" "C:\Windows"
Upvotes: 1