批处理禁用和启用服务

来源:百度文库 编辑:神马文学网 时间:2024/04/28 05:21:34
2009年12月22日 星期二 下午 02:22
批处理利用sc禁用和启用服务
sc config 服务名称 start= auto(自动)
sc config 服务名称 start= demand(手动)
sc config 服务名称 start= disabled(禁用)
然后配合 net start 服务名称或者 net stop 服务名称 来使用
例子:
sc config shellhwdetection start= disabled    禁用shellhwdetection服务。
sc config shellhwdetection start= auto          设置shellhwdetection服务自动启动。
sc config shellhwdetection start= demand    设置shellhwdetection服务手动启动。
sc start shellhwdetection                              启动shellhwdetection服务。
sc stop shellhwdetection                              停止shellhwdetection服务。
sc delete shellhwdetection                           删除shellhwdetection服务。
sc create Tomcat binPath= F:\apache-tomcat\bin\startup.bat start= auto     添加Tomcat服务。
sc config MSSQL$SQLEXPRESS start= auto           设置SQL Server (SQLEXPRESS)服务自动启动
sc config MSSQL$SQLEXPRESS start= demand     设置SQL Server (SQLEXPRESS)服务手动启动
sc config MSSQL$SQLEXPRESS start= disabled     禁用SQL Server (SQLEXPRESS)服务
net start "SQL Server (SQLEXPRESS)"                   启动SQL Server (SQLEXPRESS)服务
net stop "SQL Server (SQLEXPRESS)"                   停止SQL Server (SQLEXPRESS)服务
net pause "SQL Server (SQLEXPRESS)"                暂停SQL Server (SQLEXPRESS)服务
(如果服务名由两个或多个单词组成,必须用引号把该服务名圈起来,如:sc config "ECShop httpd" start= demand)
sc config MSISerer start= demand & net start "Windows Installer"
意思是:将 Windows Installer 服务设置为手动并启动该服务(Windows Installer的真实服务名是MSISerer)
注:
★★1)服务名不一定是你在服务面板看到的那个名。
例如,你要打开被禁用的telnet服务,sc config telnet start= auto,会报错:[SC] OpenService FAILED 1060,因为telnet的服务名不是telnet而是tlntsvr,改为sc config tlntsvr start= auto就OK了,在服务里查看telnet服务的属性,在属性框的最上面可看到真正的服务名,即命令中的服务名。
2)start=后面有一个空格,如果不加这个空格,命令就无法执行,而且连错误提示也没有, 等号后加一个空格就好了.
 
其它见微软官方说明:
http://technet.microsoft.com/zh-cn/library/cc772676(WS.10).aspx#BKMK_config
或参考:http://xygood.blog.163.com/blog/static/1135326672009713111830695/