Install windows service without InstallUtil.exe

前端 未结 8 2181
我寻月下人不归
我寻月下人不归 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:05

    You can still use installutil without visual studio, it is included with the .net framework

    On your server, open a command prompt as administrator then:

    CD C:\Windows\Microsoft.NET\Framework\v4.0.version (insert your version)
    
    installutil "C:\Program Files\YourWindowsService\YourWindowsService.exe" (insert your service name/location)
    

    To uninstall:

    installutil /u "C:\Program Files\YourWindowsService\YourWindowsService.exe" (insert your service name/location)
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-07 23:11

    Why not just create a setup project? It's really easy.

    1. Add a service installer to the service (you do it on the seemingly useless service "design" surface)
    2. Create a setup project and add the Service output to the setup app folder
    3. Most importantly add the Service project output to all the custom actions

    Voila, and you're done.

    See here for more: http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx

    There is also a way to prompt the user for credentials (or supply your own).

    0 讨论(0)
  • 2020-12-07 23:12

    Topshelf is an OSS project which was started after this question was answered and it makes Windows service much, MUCH easier.I highly recommend looking into it.

    http://topshelf-project.com/

    0 讨论(0)
  • 2020-12-07 23:16

    Not double click, you run it with the correct command line parameters, so type something like MyService -i and then MyService -u to uninstall it`.

    You could otherwise use sc.exe to install and uninstall it (or copy along InstallUtil.exe).

    0 讨论(0)
  • 2020-12-07 23:17

    This Problem is due to Security, Better open Developer Command prompt for VS 2012 in RUN AS ADMINISTRATOR and install your Service, it fix your problem surely.

    0 讨论(0)
提交回复
热议问题