If a batch script contains the pause command, but executing the script flashes but then not pauses is caused if there is a syntax error in the script.
For example, your script uses if exists filename echo test
,
but in reality it is if exist filename echo test
the script will give a syntax error and not execute properly.
To troubleshoot your script, open a command prompt, navigate to the script, and type in the command you want to test, for example: mybatch.cmd
.
This will display the error in the script and return to the existing command prompt, keeping the error on screen.
The Runas will always launch it in a new window but as long as there's no syntax error in the script, which was tested in the previous step, the pause will work there. In that case you can now try and use: runas /user:myuser mybatch.cmd
.
runas
is supposed to ask for the password before running the batch file. Does this username have a password? Does it work from an elevated CMD?