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.