Install Windows Service created in Visual Studio

前端 未结 7 692
Happy的楠姐
Happy的楠姐 2020-12-02 06:16

When I create a new Windows Service in Visual Studio 2010, I get the message stating to use InstallUtil and net start to run the service.

I have tried the following

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 06:38

    You need to open the Service.cs file in the designer, right click it and choose the menu-option "Add Installer".

    It won't install right out of the box... you need to create the installer class first.

    Some reference on service installer:

    How to: Add Installers to Your Service Application

    Quite old... but this is what I am talking about:

    Windows Services in C#: Adding the Installer (part 3)

    By doing this, a ProjectInstaller.cs will be automaticaly created. Then you can double click this, enter the designer, and configure the components:

    • serviceInstaller1 has the properties of the service itself: Description, DisplayName, ServiceName and StartType are the most important.

    • serviceProcessInstaller1 has this important property: Account that is the account in which the service will run.

    For example:

    this.serviceProcessInstaller1.Account = ServiceAccount.LocalSystem;
    

提交回复
热议问题