Windows 8中的服务不显示消息对话框

时间:2015-06-05 02:37:14

标签: windows delphi

我使用Delphi创建一个简单的应用程序服务,该服务将在启动时显示按摩。在服务属性我设置Interactive = true。 问题是当我在Windows XP中测试它工作正常并显示对话按摩,但在Windows 8中此服务不显示按摩和服务正在运行。我已阅读此link

的问题

但仍然没有显示我的服务按摩。这是我的代码:

unit MainService;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
  Registry;

type
  TEW_Main_Service = class(TService)
    procedure ServiceAfterInstall(Sender: TService);
    procedure ServiceAfterUninstall(Sender: TService);
    procedure ServiceExecute(Sender: TService);
  private
    { Private declarations }
  public
    function GetServiceController: TServiceController; override;
    { Public declarations }
  end;

var
  EW_Main_Service: TEW_Main_Service;

implementation

{$R *.DFM}

procedure ServiceController(CtrlCode: DWord); stdcall;
begin
  EW_Main_Service.Controller(CtrlCode);
end;

function TEW_Main_Service.GetServiceController: TServiceController;
begin
  Result := ServiceController;
end;

procedure TEW_Main_Service.ServiceAfterInstall(Sender: TService);
var
  Reg: TRegistry;
  Keyms: string;
begin
  Keyms := '\SYSTEM\CurrentControlSet\Services\Eventlog\Application\' + Self.Name;
  Reg := TRegistry.Create(KEY_READ or KEY_WRITE);
  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    if Reg.OpenKey('\SYSTEM\CurrentControlSet\Services\' + Self.Name, false) then
    begin
      Reg.WriteString('Description', 'This is Service test Prototype for waranty service');
      Reg.CloseKey;
    end;
  finally
    Reg.Free;
  end;
end;

procedure TEW_Main_Service.ServiceAfterUninstall(Sender: TService);
var
  Reg: TRegistry;
  Key: string;
begin
  // Delete registry entries for event viewer.
  Key := '\SYSTEM\CurrentControlSet\Services\Eventlog\Application\' + Self.Name;
  Reg := TRegistry.Create(KEY_READ or KEY_WRITE);
  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    if Reg.KeyExists(Key) then
      Reg.DeleteKey(Key);
  finally
    Reg.Free;
end;
end;

procedure TEW_Main_Service.ServiceExecute(Sender: TService);
begin
  while not Terminated do
  begin
    ShowMessage('blablablablabla');
    Sleep(1000);
    ServiceThread.ProcessRequests(False);

  end;
end;
end.
我错过了什么吗?有没有想过这个?

0 个答案:

没有答案