Tuesday, November 9, 2010

Windows: Start or Stop a Service on remote server using wmic

WMIC has been a built-in command since XP as a interface to WMI operations. Here is a basic task , stop or start the windows service on remote server.

Run WMIC on command prompt, or Run box.
image

By default, the WMIC connect to local WMI service. If you want to connect to a remote Node.
put

/Node:yourremote Server
/User:account
enter you password.

When you run /? , you will be able to see all the built-in Objects that you can interact with.

image

Service List, it will show you all services installed on the server
image

If you want to list only those service a running, and list the name caption only (like the sql projection syntax. )

service where state=”running” get name, caption, status
image

get a specified service status, like iisadmin

image

If you want to control the service, like stop the service or restart the service. 
image

to list all the operation on the service ,
Service where name=”iisadmin” call
image

the same approach applies to the process management.

process where name=”notepad.exe” call terminate
close the notepad.exe process
to shutdown the server
terminate the winlogon.exe


Also you can use PSexec to run process on the remote server directly. http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

No comments:

 
Locations of visitors to this page