Install windows service without InstallUtil.exe

前端 未结 8 2193
我寻月下人不归
我寻月下人不归 2020-12-07 23:01

I\'m trying to deploy a windows service but not quite sure how to do it right. I built it as a console app to start with, I\'ve now turned it into a windows service project

8条回答
  •  一个人的身影
    2020-12-07 23:09

    I know it is a very old question, but better update it with new information.

    You can install service by using sc command:

    InstallService.bat:

    @echo OFF
    echo Stopping old service version...
    net stop "[YOUR SERVICE NAME]"
    echo Uninstalling old service version...
    sc delete "[YOUR SERVICE NAME]"
    
    echo Installing service...
    rem DO NOT remove the space after "binpath="!
    sc create "[YOUR SERVICE NAME]" binpath= "[PATH_TO_YOUR_SERVICE_EXE]" start= auto
    echo Starting server complete
    pause
    

    With SC, you can do a lot more things as well: uninstalling the old service (if you already installed it before), checking if service with same name exists... even set your service to autostart.

    One of many references: creating a service with sc.exe; how to pass in context parameters

    I have done by both this way & InstallUtil. Personally I feel that using SC is cleaner and better for your health.

提交回复
热议问题