# How to run psexec minimized from a VB script (VBS)

When you do ...

Set WshShell = CreateObject("WScript.Shell")
Call WshShell.Run("psexec -u administrator -p pw1234 cmd /c ipconfig > C:\Output.txt", 2, True)


... you see for a short time the command prompt window.

I've been searching the web and I've tried everything I could possibly think of to hide/minimize this window, but unfortunately without success.

Is there really no way to run psexec in a hidden/minimized window?

PS: Unfortunately Call WshShell.Run("psexec -u administrator -p pw1234 start /min cmd /c ipconfig > C:\Output.txt", 2, True) doesn't work (error message: PsExec could not start start ...).

• Did you tried something like that ? Set WshShell = CreateObject("WScript.Shell") WshShell.Run "psexec cmd /c ipconfig /all > Output.txt",0,True Jun 7, 2020 at 10:34
• Thank you very much for your answer. But does this really solve the "problem" on your computer? I still see the command prompt window. Since you've removed the authentication part -u administrator -p pw1234 the command prompt window is now only visible for a very very short time, but it still appears. If you use the whole command WshShell.Run "psexec -u administrator -p pw1234 cmd /c ping 8.8.8.8 -n 5 > C:\Output.txt", 0, True the command prompt window is still visible for a longer time, isn't it? Jun 7, 2020 at 23:11
• Yep you are right ! i just tried right now and the issue is still there ! i'm sorry if i put you in a wrong direction ! Jun 8, 2020 at 0:11

Is there really no way to run psexec in a hidden/minimized window?

I believe psexec is running minimized. The command window that is being "flashed" is likely for cmd /c. cmd /c invokes a command window separately from whatever called it.

If you want to get around this "flash" effect, one method is to wrap the second command in VBScript as well. You may wish to try:

ex. run_psexec.vbs

Set WshShell = CreateObject("WScript.Shell")
Call WshShell.Run("psexec -u administrator -p pw1234 wscript C:\path\to\ip.vbs", 2, True)


ex. ip.vbs

Set WshShell = CreateObject("WScript.Shell")
Call WshShell.Run("cmd /c ipconfig > C:\ipconfig.txt", 2, True)


Caveats

• C:\path\to\ip.vbs probably shouldn't contain spaces. Perhaps this was an issue regarding testing, but I couldn't get additional double-quotes ("") to work correctly in the script above and single-quotes (') are used for comments in VBScript.

• Using just ex. ip.vbs in conjunction with the -u and -p options to psexec caused C:\Windows\System32 to be the default directory during script testing with my user on my machine. In any case, wscript should complain with a popup showing you where it's looking for a file if it can't find the script specified.

• Great idea, and yes, it works perfectly! I didn't think there would be solution. Thank you so much. Jul 3, 2020 at 9:46
• Note: If you do Call WshShell.Run("cmd /c ipconfig > ""C:\Output File.txt""", 0, True), it works even if the file name contains spaces. Jul 3, 2020 at 9:47

I tried like that and it worked on my side !

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "cmd psexec cmd /c (Ipconfig /all & Ping www.google.com) > output.txt",0,True
'MsgBox "Done",vbInformation,"Ping Results"
WshShell.Run "output.txt"

• At first sight it looked very promising, many thanks, but unfortunately your trick just disables the functionality of psexec. I need psexec so that a normal user can execute a command that requires administrative rights (e.g. WshShell.Run "psexec -u administrator -p pw1234 cmd /c netsh interface ip show address > C:\Output.txt", 2, True). In your proposed command WshShell.Run "cmd psexec -u administrator -p pw1234 cmd /c netsh interface ip show address > C:\Output.txt", 2, True it doesn't even matter if the password is correct or not because it's not checked at all. Jun 8, 2020 at 22:17