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