请问,如何写一个程序,让它在开机的时候自动运行?要源码。

解决方案 »

  1.   

    程序启动时让它往注册表里写个key:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
      

  2.   

    有时需要让Windows在启动时自动运行你的程序,如何在程序中实现呢?     使用Regedit查找HKEY_LOCALMACHINE\Sodtware\Microsoft\Windows\CurrentVersion\Run,你会发现所有的Windows启动时调用的程序都在这里,于是你将你的程序增加在这里就可以了.名称为你的程序的标题,其值为你的程序的执行路径和文件名称.     如Interbase: 
         Interbase Server"D:\Program Files\Borland\IntrBase\BIN\ibserver.exe" 
          在程序中实现可以使用TRegIniFile或者使用TRegistry都可以.     User Registry;     Var         RegF:TRegistry; 
        begin 
             RegF:=TRegistry.Create; 
             RegF.RootKey:=HKEY_LOCAL_MACHINE; 
            try 
                  RegF.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run',True); 
                  RegF.WriteString('Interbase Server', 
                                        '"D:\Program Files\Borland\IntrBase\BIN\ibserver.exe"'); 
                   except 
                        ... 
                    End; 
                    RegF.Close;                 RegF.Free; 
        end; 
      
      

  3.   

    procedure SetAutoRun(aProgTitle,aCmdLine:string;aRunonce:bookean);
    Var
      hKey:String;
      hReg:TReginifile;
    begin
      if aRunonce then
      hkey:='Once'
    else
      hkey:='';
    hreg:=TReginifile.create('');
    hreg.Rootkey:=HKEY_LOCAL_MACHINE;
    hreg.writeString(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
    +hKey+#0,
    AProgtitle,
    aCmdLine);
    hReg.free;end;
    procedure Tform1.formcreate(Sender:Tobject);
    begin
      SetAutoRun(Application.title,Application,exename,false);
    end;
    _______________________________________________________________
    够清楚了吧!!
      

  4.   

    向注册表里写啊
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
      

  5.   

    with TRegistry.Create do //写注册表,每次启动时自动运行
       try
          RootKey := HKEY_LOCAL_MACHINE;
          OpenKey( K, TRUE );
          WriteString( 'myTray', application.ExeName );
       finally
          free;
    end;K= '\Software\Microsoft\Windows\CurrentVersion\RunServices';