Two minor questions about Windows Services

Source: Internet
Author: User

The last time I translated an article about using. Net to create a Windows Service on codeprojectArticle(It was later found that someone had translated it earlier ). Make a Windows Service todayProgramAnd record the issues.

Installation of Windows Services

After the Windows service is generated, you can use the Visual Studio tool installutil.exe to register the service. However, this is not very convenient. Therefore, you can use the Visual Studio installation project to create an installation program.

Add an installation project. Right-click solution resource manager's setup project and choose add-project output. The "add project output group" dialog box is displayed, and select your service in the project, then add "main output. You can also add other content that you want to include.

Next, right-click the setup project and choose "View"> "Custom operation". The custom operation interface is displayed. Right-click the custom operation and choose "add custom operation" from the shortcut menu, in the displayed "select items in project" dialog box, select "main output from XXXX" in "application folder.

Other properties in the setup project can also be modified, such as the title, name, and manufacturer. Other settings are not discussed here.

After the project is generated, select "generate" on the Setup project to obtain the executable installer. You can use it to install the service. During the installation process, necessary information will be added to the Registry to register the service. You can view and uninstall the installed Service in the management tools-service.

About running Windows Services

During the test of the Windows Service applet, I found some problems during the running. Assume that the service program is installed in the C: \ test \ directory. Because the service reads some configuration files and outputs some log logs, an error occurs and the configuration file cannot be found, no log is generated in the directory. The search result shows that the log is generated in the c: \ windows \ system32 directory.

Therefore, the Service must find its own installed directory, that is, the image directory of the service. Since the installation is a user-defined path, you must use other methods. Here, by querying the registry, every Windows Service must add relevant information in the registry, including the service name, description, and image directory. Therefore, first obtain the image directory through the Microsoft. win32.registry class, and then read the configuration file or generate log.

This can solve this problem. But I don't know if there are any better methods. For example, directly obtain the absolute position of the EXE in the program. In the past, the winforms program can be obtained through the startuppath attribute of the system. Windows. Forms. Application class, but this method cannot be used in Windows Services.

 

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.