我需要在开机时就自动运行程序(就象qq等),怎么做呢?还有我要在我的程序里检测某个update.exe程序是否正在运行,怎么检测呢?

解决方案 »

  1.   

    使用注册表编辑器
    在RUN中设立一个主键,值为你自己程序的安装路径和文件名
    var
    reg:TRegistry;
    key:string;
    begin
    Application.ShowMainForm:=false;
    reg:=TRegistry.Create();
    reg.RootKey:=HKEY_LOCAL_MACHINE;
    Application.ShowMainForm:=false;
    reg:=TRegistry.Create();
    reg.RootKey:=HKEY_LOCAL_MACHINE;
    REG.OpenKey('Software\microsoft\currentversion\run(  具体找一下,我这个路径可能不对)',TRUE);
    reg.CreateKey(‘TEMP’);
    IF KEY<>'0' THEN
    BEGIN
    TRY
    REG.WriteString('TEMP','路径');
    EXCEPT
    SYSTEM.Exit;
    检测程序用API函数
    到文档查一下
      

  2.   

    写入注册表中.
    procedure TForm1.FormCreate(Sender: TObject);  var reg:TRegistry;
     temp:Integer;
    begin  s:=min;
      reg:=Tregistry.Create;
     try
     reg.RootKey:=HKEY_CURRENT_USER;
     if reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\RunOnce',True) then
      begin
      reg.WriteString('system','"'+ParamStr(0)+'"');
      reg.CloseKey;
      end;
      finally
      reg.Free;
      SystemParametersInfo(Spi_screensaverrunning,1,@temp,0);
      Form1.Hide;
     end
      

  3.   

    const
      MYAPPNAME ='update.exe';
    var
      RvHandle : hWnd;  ……
      RvHandle := FindWindow(MYAPPNAME, nil);
      if RvHandle > 0 then
      begin
        //正在运行
      end
      else
        //没有运行
      

  4.   

    写入注册表中.
    procedure TForm1.FormCreate(Sender: TObject);
    var
      reg:TRegistry;
      temp:Integer;
      strKey:string;
    begin    
      reg:=Tregistry.Create;
      try
        reg.RootKey:=HKEY_CURRENT_USER;
        strKey:='\Software\Microsoft\Windows\CurrentVersion\Run';
          {或者Reg.RootKey:=HKEY_USER;
              strKey:='.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Run';}
          {或者Reg.RootKey:=HKEY_LOCAT_MACHINE;
              strKey:='\Software\Microsoft\Windows\CurrentVersion\Run';}
        if reg.OpenKey(strKey,True) then
        begin
          reg.WriteString('你的键名','"'+ParamStr(0)+'"');
          reg.CloseKey;
        end;
      finally
      reg.Free;
    end;
      

  5.   

    那个检测某个应用程序有没有运行的程序不行呀,RvHandle总是返回0,还有别的方法吗?
      

  6.   

    WINXP繁體版下: "開始"---程式集---啟動(加個快捷方式就可以了)
      

  7.   

    檢查程序是否正在运行:
    program Project1;uses
      windows,
      Forms,
      Umain in 'Umain.pas' {Mainform},
      U1 in 'U1.pas' {F1},
      U2 in 'U2.pas' {F2};{$R *.res}
    const classname='tmainform';
    var
      handle:integer;begin
      handle:=findwindow(classname,nil);
      if handle<>0 then
      begin
        messagebox(0,'該程序已經有一個在運行中!','運行',0);
        halt;
      end;
    //這是檢查現在的程式是否已經運行,那麼只要把程式的名稱寫進去就ok
      Application.Initialize;
      Application.CreateForm(TMainform, Mainform);
      Application.CreateForm(TF1, F1);
      Application.CreateForm(TF2, F2);
      Application.CreateForm(Tf3, f3);
      Application.CreateForm(Tf4, f4);
      Application.Run;
    end.
      

  8.   

    我不是要检测是否该程序已经运行了一个实例,而是要该程序去检测任意exe应用程序是否运行,比如检测qq呀,金山词霸呀是否已经运行。
      

  9.   

    开机自动运行放注册表的run下是一个办法,放在service/CurrentControlSet中也可以(win2k/xp),当作一个服务来加载,可以参考诺顿/瑞星之类的做法 总之入口很多
    FindWindow('form1', 'TForm1');还有一个方法就是用在工程文件中CreateMutex 创建一个互斥变量
    然后 用GetLastError 的返回值来判断是不是ERROR_ALREADY_EXISTS.是就说明已经存在