天天看點

SC指令---安裝、開啟、配置、關閉windows服務 bat批處理

一、直接使用cmd來進行服務的一些操作

1、安裝服務

sc create test3 binPath= "C:\Users\Administrator\Desktop\win32srvDemo\win32srvdemo\Debug\win32srvDemo.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:\Users\Administrator\Desktop\win32srvdemo\win32srvdemo\Debug\win32srvdemo.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