Restart services Remotely


To proceed with this we will need Pstools, can be downloaded here http://technet.microsoft.com/en-us/sysinternals/bb896649

We will use PsExec v1.98 to Execute processes remotely.

Run from command line psexec /? to check all the functions that are available.

D:\PSTools>psexec /?
PsExec v1.98 – Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals – http://www.sysinternals.com

PsExec executes a program on a remote system, where remotely executed console
applications execute interactively.
Usage: psexec [\\computer[,computer2[,…] | @file]][-u user [-p psswd][-n s][-l
][-s|-e][-x][-i [session]][-c [-f|-v]][-w directory][-d][-<priority>][-a n,n,…
] cmd [arguments]

To start a command line remotely run from comand line

D:\PSTools>psexec \\servername cmd
PsExec v1.98 – Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals – http://www.sysinternals.com
Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.

C:\WINDOWS\system32>cd\

At this point we can execute everything in the remote server.

In this example we want to restart Terminal Services Service, to do it we run this command:

C:\>net stop termservice
The requested pause, continue, or stop is not valid for this service.
More help is available by typing NET HELPMSG 2191.
C:\> NET HELPMSG 2191
The requested pause, continue, or stop is not valid for this service.
EXPLANATION
This command is invalid for this service, or the service cannot accept the comma nd right now.

ACTION
If the service normally accepts this command, try typing it again later.

In this case the service does not allow the restart so we have to Kill and start again that service, to proceed we will use tasklist and taskkill.

C:\>tasklist /svc

Image Name                     PID Services
========================= ======== ============================================
System Idle Process              0 N/A
System                           4 N/A
smss.exe                       424 N/A
.
svchost.exe                   5700 TermService
logon.scr                     7868 N/A
PSEXESVC.EXE                   620 PSEXESVC

In the output there are multiple services running, and some info was cut to simplify the post.

The Information that interest us is this one “svchost.exe     5700 TermService”

To Kill the process run this:

C:\>taskkill /pid 5700
ERROR: The process with PID 5700 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).

C:\>taskkill /pid 5700 /F
SUCCESS: The process with PID 5700 has been terminated.

To Start the service run this:

C:\>net start termservice
The Terminal Services service is starting.
The Terminal Services service was started successfully.

or  this:

C:\>sc start termservice

SERVICE_NAME: termservice
        TYPE               : 20  WIN32_SHARE_PROCESS
        STATE              : 2  START_PENDING
                                (NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN))

        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x7d0
        PID                : 4728
        FLAGS              :

Don’t forget to exit the session in the remote server.

C:\>exit
cmd exited on tbpbdf02 with error code 0.

Hope that this information can be useful

Advertisements

About rodvars
Been working in IT Services/Consulting for the past 15 years. My main areas of work are planning, development, managing and administration System infrastructures focusing on optimizing user processes, enforcing business security, performance enhancements, high availabilty and infrastucture scalability.

2 Responses to Restart services Remotely

  1. Surpriya says:

    When I logged on to a server, its Patrol Agent was in stopping state. Tried every method to bring it up…. including this but was unsuccessful. Please Help.

    • rodvars says:

      Try to use process explorer.
      http://technet.microsoft.com/en-us/sysinternals/bb896653

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: