@echo off
::設定服務名稱
set service_name=ServiceManagement
::設定服務描述
set service_description=檔案安全上傳服務
::設定服務程式路徑
set prog_path=%cd:\=\\%\\ServiceManagement.exe
::設定服務的啟動方式 auto:自動 demand:手動 disabled:禁用
set strt=auto
echo EasyService 一鍵服務
echo ===========================================================
::pause
::======================以下部分勿隨意修改==========================
set s32=%cd%\system32
set reg_file=EasyService.reg
net stop %service_name% 2>nul
::設定服務名稱
set service_name=ServiceManagement
::設定服務描述
set service_description=檔案安全上傳服務
::設定服務程式路徑
set prog_path=%cd:\=\\%\\ServiceManagement.exe
::設定服務的啟動方式 auto:自動 demand:手動 disabled:禁用
set strt=auto
echo EasyService 一鍵服務
echo ===========================================================
::pause
::======================以下部分勿隨意修改==========================
set s32=%cd%\system32
set reg_file=EasyService.reg
net stop %service_name% 2>nul
copy instsrv.exe %s32%
copy srvany.exe %s32%
%s32%\instsrv.exe %service_name% remove 2>nul
%s32%\instsrv.exe %service_name% %s32%\srvany.exe >nul
::設定服務的啟動方式 auto:自動 demand:手動 disabled:禁用
sc config %service_name% start= %strt%
sc description %service_name% "%service_description%"
echo 生成登錄檔檔案...
echo Windows Registry Editor Version 5.00 > %reg_file%
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\%service_name%\Parameters] >> %reg_file%
echo "Application"="%prog_path%" >> %reg_file%
echo 匯入登錄檔檔案...
%reg_file%
net start %service_name%
echo ===========================完成============================
pause
copy srvany.exe %s32%
%s32%\instsrv.exe %service_name% remove 2>nul
%s32%\instsrv.exe %service_name% %s32%\srvany.exe >nul
::設定服務的啟動方式 auto:自動 demand:手動 disabled:禁用
sc config %service_name% start= %strt%
sc description %service_name% "%service_description%"
echo 生成登錄檔檔案...
echo Windows Registry Editor Version 5.00 > %reg_file%
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\%service_name%\Parameters] >> %reg_file%
echo "Application"="%prog_path%" >> %reg_file%
echo 匯入登錄檔檔案...
%reg_file%
net start %service_name%
echo ===========================完成============================
pause
儲存為bat,將需要註冊的程式和bat+instsrv.exe+srvany.exe放到同一個目錄裡邊執行bat就可以
連結: https://pan.baidu.com/s/1pLdf7oJ 密碼: ajmi
方式2:Topshelf
1.建立 console application Name XXserver
2.Install-Package Topshelf
3.新增邏輯程式碼
4.XXserver.ext install
5.XXserver.ext start --啟動服務