C # create, install, and delete Windows Services. After the user logs out, the program continues to run)

Source: Internet
Author: User

Reprinted from: http://www.cnblogs.com/gfwei/archive/2009/01/16/889878.html

Original Author:Gu Feng haoyue

 

OneProgramYou need to run the program on the server. After editing, you can run the program on the server and find that there is no problem when you log on to the program remotely. But after 10 minutes, the remote server is automatically logged out, the program is terminated. In this way, the program will not work normally. After thinking about the solution for more than a day, I finally solved the problem today.

First, write a service using. net.

Create a service, right-click on the design page, and select add installer after the menu appears. A new page is displayed, with the following controls: serviceprocessinstaller1 and serviceinstaller1.

Change the attribute account to LocalSystem in serviceprocessinstaller1.

Change the attribute parent to serviceprocessinstaller1 in serviceinstaller1. The servicename attribute is the name (set the name to Gogo) after the service is generated)

After modifying the properties of the control. Go back to the background of the new service page and add the followingCode:

PROCESS p = new process ();
P. startinfo. filename = "program path and file name ";
P. Start ();

After the token is completed, generate the token (fake name is w2.exe ). Find the generated EXE file in the corresponding folder, and find the two. EXE files with short names. Copy the file to the root directory of the drive F in a folder.

Install a service. Go to the CMD screen and enter the framework2.0 file, for example:

Cd c: \ WINDOWS \ Microsoft. NET \ framework \ v2.0.50727

After hitting

Installutil F: \ w2.exe. the uninstallation service is installutil F: \ w2.exe-U.

Now you have to start the service.

Net start Gogo, and the service starts. The service is opened, and the program that I run is opened by the System user, in this way, the program I need will not be terminated because the user is logged out. Then, the Gogo service will end, because it only plays a transitional role, saves some resources for the server.

 

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.