SC命令---安装、开启、配置、关闭windows服务 bat批处理

一、直接使用cmd来进行服务的一些操作

1、安装服务

sc create test3 binPath= "C:UsersAdministratorDesktopwin32srvDemowin32srvdemoDebugwin32srvDemo.exe"

其中:test3为创建的服务名,binPath后面是运行exe文件的所在路径

2、配置服务

有以下集中方式:(等号与值之间有个空格,不能省略)
sc config 服务名 start= AUTO    (自动)
sc config 服务名 start= DEMAND  (手动)
sc config 服务名 start= DISABLED(禁用)

例如下面的命令,在XP系统中开机便会自动启动:

sc config test3 start= AUTO

3、开启服务

net start test3

4、关闭服务

net stop test3

5、删除服务

sc delete test3

二、为方便使用,可编辑为bat批处理文件

(新建一个txt文件,自己命名,把后缀改为.bat文件)

1、创建、配置、开启服务

@echo.服务启动......
@echo off
@sc create test3 binPath= "C:UsersAdministratorDesktopwin32srvdemowin32srvdemoDebugwin32srvdemo.exe"
@net start test3
@sc config test3 start= AUTO
@echo off
@echo.启动完毕!
@pause


2、关闭服务

@echo.服务关闭
@echo off
@net stop test3
@echo off
@echo.关闭结束!
@pause


3、删除服务

@echo.服务删除
@echo off
@sc delete test3
@echo off
@echo.删除结束!
@pause

原文地址:https://www.cnblogs.com/sanduzxcvbnm/p/14658926.html