Windows service starts a program with an interface

Source: Internet
Author: User

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

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.