简单的说:
  这个例子显示了如何让Windows在启动时运行你的程序。
procedure TForm1.WMEndSession(var Message: TWMEndSession);
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\RunOnce', True) then
   begin
      Reg.WriteString('MyApp','"' + ParamStr(0) + '"');
      Reg.CloseKey;
    end;
  finally
    Reg.Free;
    inherited;
  end;end;为了能调用这个方法,它必须声明在你主窗体的Class下:^_^
private  procedure WMEndSession(var Msg:TWMEndSession); message WM_ENDSESSION;{这应该是一个Windows要关闭的消息}

解决方案 »

  1.   

    如何当你的程序运行时,再RunAtOnce下面加入一个键这样当Windouws关闭后
    可以重新运行你的程序!
      

  2.   

    看得懂,但翻译还真不知道(高考语文不及格^_^)。------------------------当Windows启动的时候,它自动读取注册表的HKLM\...\RunOnce建底下的子键,并运行该子键所对应的程序,然后把该子键删除。上面的程序截获消息WM_ENDSESSION,以在Windows关闭时得到通知,当Windows关闭时,程序自动在RunOnce键底下建立一个子键,这样下次Windows启动时就自动启动这个程序,这样一直循环,你的程序永远在Windows启动之前启动。-------------------------实际上我认为这段代码有问题,应该在RunOnce下面建立子键而不是设置它的值。
      

  3.   

    这个程序在Windows的Explorer.exe启动之前启动,也就是在桌面加载之前启动,而且在没有结束这个程序之前,Explorer.exe不会被启动。
      

  4.   

    同意 BCB_FANS(四大名捕之追杀令) 所解释,正是如此。另:
    该键值也可用在程序非正常退出后,重启Windows时你的程序可以自动运行。
    具体实现方法:
      (1)、程序启动时在runonce键中写入你的程序。
     (2)、程序退出时删除该键值。
    实现原理:
      因为你的应用程序如非正常退出后,该键值未删除。Windows重新启动后,其会读取该键值,并运行你的程序。然后删除该键值,从而实现只运行一次。
      

  5.   

    这段程序是当你的应用程序正在运行时就被关机,当下次Windows启动时还会打开那个应用程序
      

  6.   

    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.
    这段程序是当你的应用程序正在运行时就被关机,当下次Windows启动时还会打开那个应用程序
     When Windows starts up, it launches each application listed in the RunOnce key and then deletes the entry for that application.
    当Windows启动时它将运行所有在RunOnce键里列出的程序,并删除该程序的入口。
    Therefore, you do not need to remove the entry written here.
    所以,你不用(自己)去掉在那里(RunOnce)写的程序入口。
      

  7.   

    你的应用程序正在运行,这时突然关机了(由于某种原因);但当你再次开机时,你的应用程序就会接着关机前运行。(我看类似Word)下面是其实现原理:当Windows启动的时候,它自动读取注册表的HKLM\...\RunOnce建底下的子键,并运行该子键所对应的程序,然后把该子键删除。
    为了能调用这个方法,它必须声明在你主窗体的Class下:
    private  procedure WMEndSession(var Msg:TWMEndSession); message WM_ENDSESSION;{这应该是一个Windows要关闭的消息}
      

  8.   

    也不太准确,请多指正。
    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.
    翻译一下:
    下面的例子显示:当你的程序运行而系统关闭,这时当你重新启动windows时,该程序重新启动。当windows启动时,他把每个应用程序列表放置在runonce键中,然后删除应用程序的入口 ,但是你不必删除写在这里的键值
      

  9.   

    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.下面的例子显示了假如你的应用程序在系统关闭时处在运行状态,如何告诉Windows启动时重新载入你的应用程序.当Windows启动时,它装载列示在RunOnce键的每一个应用程序然后删除该应用程序的条目(key).因此,你不必自己去删除这里所写的条目(就是key了).                                       --什么翻译都有,快faint了!
      

  10.   

    "它是如何删除注册表里的这些东西",我上面不是已经说了吗???“当Windows..............运行该子键所对应的程序,然后把该子键删除。”
    是Windows去删除,而不是程序本身去删除。
      

  11.   

    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.下面这个例子是让Windows如何在启动的时候重新装在当Windows关闭时还在运行的程序。当Windows启动时,它将运行每一个在RunOnce键值里面所列出的程序,然后删除改应用程序的条目,因此,你不需要在这里写删除键值的程序。