5

I am looking for a method of starting/stopping a service on a remote Windows 2003 Server. Locally I know that the net command works, but is there a way to do this over the network?

EDIT: Looking to be able to do this in a script, external GUI tools won't work unless they have a command line tool.

MagicKat
  • 153

8 Answers8

8

Use the "sc.exe" command from the Windows Server Resource Kit.

An example, to configure a the IIS service to Autostart and then to start it:

sc \\server1 config w3svc start= auto
sc \\server1 start w3svc
Ryan Fisher
  • 2,226
6

There is a free sysinternals tools called PsService that allows you to view status, start, stop services locally and on other machines.

David Yu
  • 1,032
1

Use the sc command:

sc [server] [command] [service name]
squillman
  • 38,013
1

You could use the sc command.

Basically:

sc \\server stop wuauserv

sc \\server start wuauserv

For more info just type sc in a command prompt.

ThatGraemeGuy
  • 15,588
0

Start your Services administration tool on your local machine, right click on the "Services (Local)" entry and connect to the remote computer

This will give you the full services MMC for the remote machine

Kevin Kuphal
  • 9,154
0

If you're UNIXy at heart and working with Windows servers, do what I do. Install cygwin, configure opensshd and ssh in to use net start / net stop.

Kyle
  • 1,879
0

Obviously `sc' has been touched upon quite frequently, here's an alternative for you:

There's a GREAT group of utilities out there written by Mark Russinovitch called "PSTools" which has that capability. Specifically `psexec' can do that for you.

Greg Meehan
  • 1,166
0

Also, i found this Powershell script on the net:

####################################################################################
#PoSH script to check if a server is up and if it is check for a service.
#If the service isn't running, start it and send an email
# JK - 7/2009
#Updated: 07/22/09 by Steven Murawski (http://blog.usepowershell.com)
#Changed the ping result comparison to use the .NET Enum
####################################################################################

$erroractionpreference = "SilentlyContinue"

$i = "testserver"   #Server Name
$service = "spooler"    #Service to monitor

 $ping = new-object System.Net.NetworkInformation.Ping
    $rslt = $ping.send($i)
        if ($rslt.status –eq [System.Net.NetworkInformation.IPStatus]::Success)
{
        $b = get-wmiobject win32_service -computername $i -Filter "Name = '$service'"

    If ($b.state -eq "stopped")
    {
    $b.startservice()

    $emailFrom = "services@yourdomain.com"
    $emailTo = "you@yourdomain.com"
    $subject = "$service Service has restarted on $i"
    $body = "The $service service on $i has crashed and been restarted"
    $smtpServer = "xx.yourdomain.com"
    $smtp = new-object Net.Mail.SmtpClient($smtpServer)
    $smtp.Send($emailFrom, $emailTo, $subject, $body)
    }

}
djangofan
  • 4,200