KaraUL
KaraUL

Reputation: 13

Why cannot i use batch XCOPY while running in admin mode?

i have run very simple script: xcopy some.exe c:\folder\ /h/y and it works normally. but when i try to run .bat file with this code as administrator - cmd line opens for a moment but nothing happens (file not copied). Can anyone explain this issue?

i also tried to use echo xcopy instead of xcopy, but nothing had changed.

i need only admin running of .bat file, cause i want to copy file in \windows\system32 folder

Upvotes: 1

Views: 2399

Answers (1)

Stephan
Stephan

Reputation: 56180

when you start a batchfile as administrator, it's working directory is C:\windows\system32\. So your script doesn't find your file. Either work with absolute paths, or change the working directory.

You can change it to the directory, where your batchfile resides with:

cd /d "%~dp0"

Note: to keep the window open to read any errormessages, append a pause command.

Upvotes: 3

Related Questions