如何使用bat命令开启关闭服务?
net和sc,
net用于打开没有被禁用的服务,语法是:启动netstart服务名停止netstop服务名用sc可打开被禁用的服务,语法是:scconfig服务名start=demand//手动sccondig服务名start=auto//自动scconfig服务名start=disabled//禁用scstart服务名scstop服务名注:1)服务名不一定是你在服务面板看到的那个名,例如,你要打开被禁用的telnet服务,
scconfigtelnetstart=auto,
报错:OpenServiceFAILED1060
,因为telnet的服务名不是telnet而是tlntsvr,scconfigtlntsvrstart=auto就OK了,在服务面板里查看telnet属性,从可执行文件的路径里可看到服务程序名,即命令中的服务名。2)start=后面有空格,少了就有错sc.exe命令功能列表: 注:以下命令中。=号后面都有一个空格,=号前面没有空格! 1.
更改服务的启动状态(这是比较有用的一个功能) 2.
删除服务(除非对自己电脑的软、硬件所需的服务比较清楚,否则不建议删除任何系统服务,特别是基础服务) 3.
停止或启动服务(功能上类似于netstop/start
,但速度更快且能停止的服务更多)
具体的命令格式如下:
修改服务启动类型的命令行格式为(特别注意start=后面有一个空格) scconfig服务名称start=demand(
设置服务为手动启动) scconfig服务名称start=disabled(
设置服务为禁用) 停止/启动服务的命令行格式为 scstop/start服务名称
注意:平时常接触的都是服务的显示名称,而以上所指是服务名称,都可以在控制面板-管理工具-服务里面,双击对应的服务来查询。
先举例说明一下具体的设置方法:
如设置远程注册表服务为手动其格式为 scconfigRemoteRegistrystart=demand
设为禁用的格式为: scconfigRemoteRegistrystart=disabled
停止服务则格式为: scstopRemoteRegistry
首先把自己所需设置的服务名称查到之后,按照上面的格式做成批处理文件,重装系统之后只要运行批处理文件即可。
以下是我的设置,以XpSp2为蓝本,可比对所用的系统进行增删和修改。注:未加入XpSp2的自动更新、安全中心、防火墙。 scconfigAlerterstart=demand scconfigTrkWksstart=demand scconfighelpsvcstart=demand scconfigpolicyAgentstart=demand scconfigdmserverstart=demand scconfigWmdmpmSnstart=demand scconfigSpoolerstart=demand scconfigRemoteRegistrystart=demand scconfigNtmsSvcstart=demand scconfigseclogonstart=demand scconfigSchedulestart=demand scconfigWebClientstart=demand scconfigW32Timestart=demand scconfigWZCSVCstart=demand scconfigERSvc
start=demand scconfigThemesstart=demand scconfigFastUserSwitchingCompati
bilitystart=disabled scconfigMessengerstart=disabled scconfigprotectedStoragestart=disabled scconfigSSDpSRVstart=disabled scconfigTermServicestart=disabled scconfigShellHWDetectionstart=disabled
如果需要立即关闭服务也可把以下代码跟在上面的代码之后 scstopW32Time scstopShellHWDetection scstopTrkWks scstophelpsvc scstopdmserver scstoppolicyAgent scstopSpooler scstopRemoteRegistry scstopseclogon scstopSchedule scstopWZCSVC scstopERSvc scstopThemes scstopFastUserSwitchingCompatibility scstopprotectedStorage scstopSSDpSRV scstopWebClient
最后把修改好之后的代码存为