Running batch file with runas command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
fatal.lordes
Posts: 5
Joined: 30 Mar 2010 18:07

Running batch file with runas command

#1 Post by fatal.lordes » 30 Mar 2010 18:14

Hi all

I've written a batch file that uses the runas command. The command I've used works when I test it in CMD less the runas part but when it's in the batch file and I use the runas part, it works but it pops up a screen really quick with the results and then it disappears and then another box appears and the pause is there. I'm wondering if anyone has any tips or tricks on how to get the results of the batch to display, either to screen or text (tried piping but I'm obviously doing it wrong as it doesn't work again when using the runas part), I'd appreciate it.

Here's the batch:

SET /p PCASSET=Please type the asset :
RUNAS /U:DESQLD\USERNAME_ADMIN "REG QUERY \\%PCASSET%\HKEY_LOCAL_MACHINE\SOFTWARE\DES\CustomData /s"
ECHO.
PAUSE

Its driving me batty! Something that I thought would be so simple has proven more tricky than I thought.

Thanks in advance.

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: Running batch file with runas command

#2 Post by avery_larry » 31 Mar 2010 11:09

Code: Select all

RUNAS /U:DESQLD\USERNAME_ADMIN "cmd /k \"REG QUERY \\%PCASSET%\HKEY_LOCAL_MACHINE\SOFTWARE\DES\CustomData /s\" "

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: Running batch file with runas command

#3 Post by avery_larry » 31 Mar 2010 11:26

Better:
Will pause pretty much no matter what:

Code: Select all

RUNAS /U:DESQLD\USERNAME_ADMIN "cmd /c \"REG QUERY \\%PCASSET%\HKEY_LOCAL_MACHINE\SOFTWARE\DES\CustomData /s ^& pause\" "


Will pause only if it is successful:

Code: Select all

RUNAS /U:DESQLD\USERNAME_ADMIN "cmd /c \"REG QUERY \\%PCASSET%\HKEY_LOCAL_MACHINE\SOFTWARE\DES\CustomData /s ^&^& pause\" "


Will pause only if it fails:

Code: Select all

RUNAS /U:DESQLD\USERNAME_ADMIN "cmd /c \"REG QUERY \\%PCASSET%\HKEY_LOCAL_MACHINE\SOFTWARE\DES\CustomData /s ^|^| pause\" "

fatal.lordes
Posts: 5
Joined: 30 Mar 2010 18:07

Re: Running batch file with runas command

#4 Post by fatal.lordes » 31 Mar 2010 14:58

Perfect! Thanks so much! :)

Post Reply