This is a creation in Article, where the information may have evolved or changed.
Problem Description: After the server logs off, all running. exe files associated with the user are exited, which is why the. exe program for the GO website is closed
Workaround: Through the Windows service
There are many ways to make Windows services online, but not all EXE files can be serviced, and the. exe on the go build just can't! So, it can only be done in another way: using. NET to build a service project, In this service project to monitor the operation of the Go Web. exe program, if the go site's. exe program stops, then immediately start it in the Windows service, so even if the logoff is not afraid.
Details are as follows:
1) Go build exe file (my in D:\Go\src\myweb\myweb.exe)
2) Establish Windowsservice project (note version)
Core code:
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.diagnostics;using system.linq;using system.serviceprocess;using system.text;using System.Threading.Tasks; Using System.timers;namespace bdiaservice{public partial class Bdia:servicebase {public Bdia () { InitializeComponent (); }///<summary>//The function that is called when the service starts///</summary>//<param name= "args" >< /param> protected override void OnStart (string[] args) {Check2 ();//Start MyWeb application Tim er t1 = new Timer (60000); T1. Elapsed + = new Elapsedeventhandler (check);//Check T1 once every 1 minutes. Start (); Start the timer. }///<summary>//When the service is stopped, close the MyWeb///</summary> protected override void on Stop () {process[] myprocess = Process.getprocessesbyname ("MyWeb"); if (myprocess. LengtH > 0) {myprocess[0]. CloseMainWindow (); Myprocess[0]. Close (); }}///<summary>///Timer execution function///</summary>//<param name= "O" >< /param>//<param name= "E" ></param> public void Check (Object o, Elapsedeventargs e) {process[] myprocess = Process.getprocessesbyname ("MyWeb");//Get the process with the name MyWeb if (myprocess. Length > 0)//If present, the description has been started {//off//myprocess[0]. CloseMainWindow (); Myprocess[0]. Close (); } else//otherwise start Myweb.exe {Process.Start (@ "D:\Go\src\myweb\myweb.exe"); }} public void Check2 () {process[] myprocess = Process.getprocessesbyname ("MyWeb" ); if (myprocess. Length > 0) {//myprocess[0]. CloseMainWindow (); // Myprocess[0]. Close (); } else {Process.Start (@ "D:\Go\src\myweb\myweb.exe"); } } }}
3) Windowsservice Project installation Deployment (as long as the. NET is installed on the computer, the following code is generally available, here is my. exe file path):
C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe D:\Go\src\myweb\myweb.exe