请高手检验一下:开机自启动的Delphi程序代码!!!

发布时间:2024-11-08 02:49 发布:上海旅游网

问题描述:

高手们帮我看看这个代码为什么运行不了~感谢!

unit Capture_main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, registry, WinProcs;

type
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure WMQueryEndSession (var Message: TMessage);
message WM_QUERYENDSESSION ;
end;

var
Form1: TForm1;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
Reg: Tregistry;
begin
RegisterServiceProcess( GetCurrentProcessID, 1 );
Reg := Tregistry.Create ;
Reg.RootKey := HKEY_LOCAL_MACHINE;
if not reg.KeyExists('SOFTWARE\monitor') then begin
Reg.CreateKey ('SOFTWARE\monitor');
Reg.Writestring('AutoRun', 'true');
Reg.OpenKey
('SOFTWARE\Microsoft\Windows\CurrentVersion\Run',true);
Reg.WriteString('monitor_server',application.ExeName );
end;
Reg.CloseKey;
Reg.Free;
end;

procedure TForm1.WMQueryEndSession (var Message: TMessage);
var
Reg: Tregistry;
begin
Reg := Tregistry.Create ;
Reg.RootKey := HKEY_LOCAL_MACHINE;
Reg.OpenKey ('SOFTWARE\monitor',true);
if Reg.ReadString('AutoRun') = 'true' then
begin
Reg.CloseKey;
Reg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run', true);
Reg.WriteString('monitor_server',application.ExeName );
Reg.CloseKey;
Reg.Free;
end;
Form1.Close;
end;

end.

问题解答:

win98支持RegisterServiceProcess
NT内核的windows nt/2000/xp/2003不支持~

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Registry;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var reg:tregistry;
begin
reg:=tregistry.create;
reg.rootkey:=HKEY_LOCAL_MACHINE;
reg.openkey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run',true);
reg.WriteString('qq','C:\WINDOWS\system32\qq.exe');
reg.closekey;
reg.free;
end;

end.

热点新闻