兔八哥极品软件园    运行: 4471天 | 文章:640 篇 | 评论:505 条 | 碎语:1条

CMD批处理命令操作服务,利用sc命令禁用和启用服务

作者:admin 发布于:2012-3-12 15:22 Monday 分类:网络转载


批处理利用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= 后面有一个空格,如果不加这个空格,命令就无法执行,而且连错误提示也没有, 等号后加一个空格就好了

 

举例:

@echo 禁用错误报告
sc config ERSvc start= DISABLED
net stop ERSvc

@echo 禁用系统帮助
sc config helpsvc start= DISABLED
net stop helpsvc

@echo 禁用打印后台
sc config Spooler start= DISABLED
net stop Spooler

@echo 禁用远程注册表
sc config RemoteRegistry start= DISABLED
net stop RemoteRegistry

@echo 禁用系统时间同步
sc config W32Time start= DISABLED
net stop W32Time

@echo 禁用无线网卡
sc config WZCSVC start= DISABLED

net stop WZCSVC

参见微软官方说明:

http://technet.microsoft.com/zh-cn/library/cc772676(WS.10).aspx#BKMK_config

标签: CMD sc 批处理 服务


Powered by 兔八哥极品软件 苏ICP备12049267号 sitemap