我正在寻找在远程Windows 2003 Server上启动/停止服务的方法。 本地我知道,networking命令的作品,但有没有办法通过networking做到这一点?
编辑:希望能够在脚本中做到这一点,外部GUI工具将无法正常工作,除非他们有一个命令行工具。
使用Windows Server资源工具包中的“sc.exe”命令。
例如,将IIS服务configuration为自动启动,然后启动它:
sc \\server1 config w3svc start= auto sc \\server1 start w3svc
有一个名为PsService的免费sysinternals工具,可以让你在本地和其他机器上查看状态,启动,停止服务。
使用sc命令:
sc [server] [command] [service name]
你可以使用sc命令。
基本上:
sc \\server stop wuauserv
sc \\server start wuauserv
有关更多信息,只需在命令提示符下键入sc 。
在本地计算机上启动您的服务pipe理工具,右键单击“服务(本地)”条目并连接到远程计算机
这将为您提供远程机器的完整服务MMC
如果你是UNIX的核心,并与Windows服务器,使用我的工作。 安装cygwin,configurationopensshd和ssh以使用net start / net stop。
很显然`sc'已经被频繁地触及了,这里有一个替代scheme:
Mark Russinovitch写的一个很棒的公用事业公司叫做“PSTools” ,它有这个能力。 特别是`psexec'可以为你做到这一点。
另外,我在网上find了这个Powershell脚本:
#################################################################################### #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 = "[email protected]" $emailTo = "[email protected]" $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) } }