You can use PSExec.exe from Microsoft to run a command remotely. PSExec.exe is part of PSTools from Microsoft which can be downloaded from here:
This tip shows how you can run a command remotely without using PSExec.exe.
Let’s say you want to run GPUpdate.exe command on a remote computer to refresh the GPO settings, use the below command:
- WMIC /node:ComputerName process call create “cmd.exe /c GPUpdate.exe”
The above command creates a process on the remote computer to execute “cmd.exe /c GPUpdate.exe” command line.
You can utilize above command to run any command remotely. You just need to replace ComputerName and “cmd.exe /c GPUpdate.exe” with a choice of your command!
About Nirmal Sharma
Nirmal is a MCSEx3, MCITP and was awarded Microsoft MVP award in Directory Services. He is specialized in Directory Services, Microsoft Clustering, Hyper-V, SQL and Exchange and has been involved in Microsoft Technologies since 1994. In his spare time, he likes to help others and share some of his knowledge by writing tips and articles. Nirmal can be reached at [email protected].
What if the executable is in a sub folder of the remote machine?
Then you simply specify the full path :
WMIC /node:ComputerName process call create “cmd.exe /c c:\path-to-your-exe\GPUpdate.exe”
I tried to open Firefox on a remote server using the following code but I receive a ReturnValue = 9. Firefox never launches.
WMIC.exe /node:ComputerName process call create “cmd.exe/C C:\Program Files\Mozilla Firefox\firefox.exe”
received error “invalid global switch”
It works but it puts the application in the background and I can’t see the window… (just the process in the task manager) (it’s a computer where I’m logged in remotely)
how can I put the window in front of everything?.. I’m trying with notepad
You help is greatly appreciated,
I am executing Test.bat file on remote server Server_2 from Server_1. Here’s portion of WMIC command on Server_1 – “cmd.exe /c \\Server_2\testDir\Test.bat”.
Test.bat has exit %errorlevel%
How can I capture %errorlevel% on Server_1? I would like to exit calling script on Server_1 with %errorlevel% returned from remote server Server_2.