If you want to run the command using different credentials, you can use the RunAs
command. Things can get tricky when embedding your command within the RunAs
command, however. These steps may help:
Determine the proper command line syntax. Test this directly at the command prompt to ensure it's correct.
c:\setup.exe /s /v"/qn"
Embed your command within the RunAs
command. Your entire command needs to be surrounded with quotes. In addition, any quotes within your command need to be escaped with \
. Again, test this directly at the command prompt to ensure it's correct.
runas.exe /user:DOMAIN\USER "c:\setup.exe /s /v\"/qn\""
Convert the entire command string to VBScript. Wherever you see a quote, double it, or replace it with Chr(34)
. Here is how it would look when the quotes are doubled:
runas.exe /user:DOMAIN\USER ""c:\setup.exe /s /v\""/qn\""""
Assign it to a VBScript variable. We just need to put additional quotes around the entire command:
strCommand = "runas.exe /user:DOMAIN\USER ""c:\setup.exe /s /v\""/qn\"""""
Now you're ready to go. You can run this directly with Shell.Run
:
With CreateObject("WScript.Shell")
.Run strCommand
End With
Note that you will still need to use SendKeys
when RunAs
prompts you for the password, as it provides no way to pass it on the command line.
An alternative method is to use SCHTASKS
to schedule a one-time task to be run immediately. With SCHTASKS
, you can pass the complete credentials on the command line.