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.

8 Answers 8

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
4
  • FWIW, sc.exe is built-in from Server 2003 onwards. Jun 1, 2009 at 21:47
  • Thanks... I thought that might be true but was too lazy to check.. ;-) Jun 2, 2009 at 21:39
  • FWIW2: the sc command that comes with XP is not compatible with the w2k3 version. Use only the w2k3 version for w2k3 servers.
    – katriel
    Jul 30, 2009 at 22:46
  • Also, using the sc "config" command to change the service startup is "start=", a space and then "auto". No, I'm not kidding. Yes, it's weird and screws me up all the time. Nov 10, 2009 at 19:15
6

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

1

Use the sc command:

sc [server] [command] [service name]
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.

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

1
  • Nevermind, I see that you're asking about non-GUI tools Jun 1, 2009 at 21:41
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.

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.

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)
    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.