When you write the Windows service daemon, you will definitely encounter the startup program without seeing the interface and only see the EXE problem.
Then there may be the following conditions
A. Whether the boot, or the program is turned off, the service starts the program can only see the EXE, not see the interface;
B. After the boot, the service automatically start the program, can only see the process has EXE, see the interface, but kill the process restart, you can see the interface;
Let me give you a solution:
1. The startup program code in the service is as follows:
String appstartpath = @ "C:\Test.exe"; IntPtr usertokenhandle = IntPtr.Zero; Apidefinitions.wtsqueryusertoken (Apidefinitions.wtsgetactiveconsolesessionid (), ref userTokenHandle); Apidefinitions.process_information procinfo = new Apidefinitions.process_information (); Apidefinitions.startupinfo startinfo = new Apidefinitions.startupinfo (); STARTINFO.CB = (UINT) marshal.sizeof (startinfo); Apidefinitions.createprocessasuser (Usertokenhandle, Appstartpath, "", IntPtr.Zero, IntPtr.Zero, False, 0, IntPtr.Zero, NULL, ref startinfo, out procinfo); if (usertokenhandle! = IntPtr.Zero) Apidefinitions.closehandle (Usertokenhandle);
Need to download Cjwdev.WindowsApi.dll, a lot of resources, their own Baidu to download
2. You must have a user who can log on without entering a password, using the command control USERPASSWORDS2 settings.
The above very simple two points, I have been tested many times. When I found out it was the law, I wouldn't tell you how excited I was.
After someone has written the code, it may be thought that there is no need to add automatic login to the 2nd user, which may be caused only by one user (no test, speculation).
The computer that needs this daemon is usually a server, and the server is generally remote. And the customer will not give you administrator account, but give you a other account.
(The general customer only looks at the program's interface, does not go to see the process, so, without the interface, he felt that the program did not start.)
So the above situation, is the evil of the client forced me to do it, and then I have to do a variety of experiments to get results.
Don't forget to praise.
Windows service starts a program with an interface