vendredi 27 février 2015

Batch Script - different when admin or not

I've been trying to copy a file using a script, and I had the following code. It displays as expected when run: C:\Users\Nico\Desktop\Stopthe.scr


If I run it as Administrator, which it needs to work correctly, it displays a different path: C:\Windows\System32\Stopthe.scr


The script is I'm testing is on the desktop.



:: don't output the commands that are running to screen
echo OFF
:: label for a goto statement - although not required atm
:start
:: clears the screen
cls
:: variable - path to where script is located
set herePath=%cd%\Stopthe.scr
:: %cd% returns the current directory of where the script is.

echo %herePath%
echo.

pause


I want to locate the path, and it returns the correct path when running normally, but when ran as administrator, it doesn't return the path to the script (but presumably where the cmd.exe is located).


I understood %cd% to return the current directory the script is in, which is what I want.


Aucun commentaire:

Enregistrer un commentaire