系统重启后自动运行程序<br><br>The following example shows how to tell Windows to relaunch your application when Windows starts up if it was running when the system shut down. When Windows starts up, it launches each application listed in the RunOnce key and then deletes the entry for that application. Therefore, you do not need to remove the entry written here.<br><br>procedure TForm1.WMEndSession(var Message: TWMEndSession);<br>var<br> Reg: TRegistry;<br>begin<br> Reg := TRegistry.Create;<br> try<br> Reg.RootKey := HKEY_CURRENT_USER;<br> if Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/RunOnce', True) then<br> begin<br> Reg.WriteString('MyApp','"' + ParamStr(0) + '"');<br> Reg.CloseKey;<br> end;<br> finally<br> Reg.Free;<br> inherited;<br> end;<br><br>end;<br><br><br><br>In order for this method to be called, it must be declared in your main form class as follows:<br><br>private<br><br> procedure WMEndSession(var Msg:TWMEndSession); message WM_ENDSESSION;