bestlong 怕失憶論壇

標題: 如何讓程式在每次開機時都執行或只執行一次 [打印本頁]

作者: bestlong    時間: 2007-12-14 08:20     標題: 如何讓程式在每次開機時都執行或只執行一次

有的時候會希望程式在電腦開機時就執行或只執行一次,可以用設定系統機碼的方式來處理

  1. Procedure OnStartup (const PgmTitle, CmdLine: String; RunOnce: boolean);
  2. Var
  3.   Key : String;
  4.   Reg : TRegIniFile;
  5. Begin
  6.   If RunOnce Then
  7.     Key := 'Once' #0
  8.   Else
  9.     Key := #0;
  10.   Reg := TRegIniFile.create ('');
  11.   Reg.RootKey := HKEY_LOCAL_MACHINE;
  12.   Reg.WriteString ('Software\Microsoft\Windows\CurrentVersion\Run' + Key, ProgTitle, CmdLine);
  13.   Reg.Free
  14. End;
複製代碼


需要下次開機執行一次 runthis.exe 程式只要呼叫 OnStartUp 函數如下方式

OnStartup('any title does not matter', 'c:\temp\runthis.exe', true);

若是需要每次開機都執行 runthis.exe 程式就可如下方式呼叫

OnStartup('any title does not matter', 'c:\temp\runthis.exe', false);


資料來源 http://www.delphifaq.com




歡迎光臨 bestlong 怕失憶論壇 (http://www.bestlong.idv.tw/) Powered by Discuz! X1.5