Windows batch file not running by "Run as administrator" in cmd prompt

I wrote simple script to install certificate saved it as install.bat.

certutil.exe -addstore "Root" "server.crt"

Both files in same folder: install.bat server.crt

Right click install.bat and select Run As Administrator, blinks very fast I can't see what was the issue but the certificate was NOT installed.

If I open Cmd prompt manually as administrator, and then manually typing install.bat, then the certificate was installed normally.

I have no idea why.


Solution 1:

When you run script from manual cmd you CD into correct folder. Run batch as admin likely runs from C:\Windows\System32 so can't find certificate file. Put pause at end of batch script to see error or timeout /t 20

Solution 2:

Solution:

certutil.exe -addstore "Root" "%~dp0server.crt"
pause
%~dp0 : this will append the full path to where your script and crt file are located
pause : will pause the execution at this point to let you see what happens before the terminal window is closed.