On Delphi Creating a Windows Service program interacting with a form implementation

Source: Internet
Author: User

The function I want to implement is to create a service program and then dynamically create a forms form when the service start, and then turn the form into TrayIcon on the Windows tray when it shrinks.

I wrote in the OnStart event of the service program

  Started: = True;  Writeworklog ('serve2   start');     Write Log  Svcmgr.Application.CreateForm (TForm1,  Form1);  Form1.show;

The log process is:

procedureWriteworklog (sqlstr:string);varFilev:textfile; ss:string;beginsqlstr:=datetimetostr (now) +'Log:'+sqlstr; SS:='D:\RunLog.txt'; ifFileExists (SS) Then  beginAssignFile (Filev, SS);    Append (Filev);  Writeln (Filev, SQLSTR); End Else beginAssignFile (Filev, SS);    ReWrite (Filev);  Writeln (Filev, SQLSTR); End; CloseFile (Filev);End;

But Form1 does not show at all, and the log shows that it is in the STARTG process. And I tested form1.showing to true, stating that the form is still displayed.

Then I tested in Form1 's OnCreate event, and the log files were displayed in the event, but they were not displayed.

Later I put a label in the Form1, in the Form1 OnCreate event label.caption re-assigned value, and then print label.caption to TXT, found that the label caption has been modified.

In fact, the form is displayed, just started in the service, not displayed on the screen. It is said that previous XP and previous systems can be replaced by Win7 now.

It is said that from Vista, the Windows kernel has made changes to the desktop interaction of the service, the account that the service runs on and the desktop of the user who is currently logged on is independent, so it is not possible to display the form in the service on the desktop.
Generally this time you will open an empty desktop to prompt you to manipulate the interactive form.
You can change the properties of the service, "login", "Login status" to the desktop user and try again.
Prior to Windows Vista, the default account for the service was system, the desktop was shared with the current interactive desktop, and Vista was invalidated.

About Delphi Creating a Windows Service program interacting with a form implementation

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.