Deploying Windows service under. net

Source: Internet
Author: User

Created service:Winservicedemo

1. Create a Windows service project, such as mywinservice.CodeImplement the functions you want to implement. As follows:

View plaincopy to clipboardprint?
String filename = @ "E: \ test \ winservice. log ";
Protected override void onstart (string [] ARGs)
{
// Todo: Add code here to start the service.
File. appendalltext (filename, "winservicedemo started", encoding. Default );
}

Protected override void onstop ()
{
// Todo: Add code here to stop the service.
File. appendalltext (filename, "winservicedemo stopped", encoding. Default );
}

2. Right-click the blank area on the winservicedemo design page, select "properties", and setSet the servicename attribute to "winservicedemo ",

3. Right-click the blank area on the winservicedemo design page and select"Add and installProgram", Go to the" projectinstaller design "view, select" serviceinstaller1 ", and set its servicename attribute to" winservicedemo ". Note: it must be the same as the servicename set in step 2. Otherwise, after packaging and installation, the service cannot be started normally. Other attributes, such as description, displayname, and starttype, are displayed on your own. If there are multiple services in this project, you need to set modifiers to public. Otherwise, the service cannot be started normally after packaging and installation.

Right-click servicepprocessinstaller1 in the project installer design view and select Properties.Account: LocalSystem

5. If the project contains multiple services, such as winservicedemo and winservice2, you also need to modify programs,

View plaincopy to clipboardprint?
Static void main ()
{
Servicebase [] servicestorun;
Servicestorun = new servicebase []
{
New winservicedemo (),
New winservice2 ()

};
Servicebase. Run (servicestorun );
}

6. Add a deployment project, such as windowsservicesetup.

7. Right-click the windowsservicesetup project, add -- project output, select the project as the main Windows Service Project to be deployed, such as "winservicedemo", and select "main output ",

8,Right-click the windowsservicesetup project, view --- custom operations, right-click the custom operations and add custom operations in the Custom operations window ", select "Application folder" ---- "main output comes from ...... (activity )",

9. Compilation and generation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.