Personal computing discussed

Moderators: Flying Fox, Ryu Connor

 
xeridea
Gerbil
Topic Author
Posts: 40
Joined: Tue Feb 22, 2011 2:25 am

Batch file as admin in specified directory.

Sat May 13, 2017 4:05 pm

I need to run a batch file as administrator. I can easily do this by right clicking or making a shortcut and changing the properties. The issue is when you do so it runs that from the Windows system directory and not the directory where the batch file resides even if I set the running directory. The only way I can run the file currently is to open a command prompt as administrator and manually browse to the file which is highly cumbersome. If I put the full path of the program I need to run in the batch file it can't seem to find it. It may be because it is in program files on their the space, I tried using quotes but wasn't able to get it to work. I am running NVSMI to quickly change power limits, and it seems to be highly annoying to do so.

Update, this works in batch file then run as admin

cd "C:\Program Files\NVIDIA Corporation\NVSMI"
nvidia-smi.exe -i 0 -pl 105
nvidia-smi.exe -i 1 -pl 105
nvidia-smi.exe -i 2 -pl 140
nvidia-smi.exe -i 3 -pl 105
pause
 
madlemming
Gerbil XP
Posts: 341
Joined: Fri Oct 15, 2004 2:22 pm

Re: Batch file as admin in specified directory.

Sat May 13, 2017 5:30 pm

%0 should be auto-filled with the name of the executed batch file.
So you can do something like:
cd %0\..

to set the working directory to the script directory.
 
jihadjoe
Gerbil Elite
Posts: 592
Joined: Mon Dec 06, 2010 11:34 am

Re: Batch file as admin in specified directory.

Sat May 13, 2017 6:03 pm

Why not just add the location of nvidia-smi.exe to %PATH% instead of messing with changing directories?

Who is online

Users browsing this forum: No registered users and 1 guest