- 註冊時間
- 2006-3-13
- 最後登錄
- 2025-1-10
- 在線時間
- 673 小時
- 閱讀權限
- 200
- 積分
- 417
- 帖子
- 1107
- 精華
- 0
- UID
- 2
  
|
有的時候會希望程式在電腦開機時就執行或只執行一次,可以用設定系統機碼的方式來處理
- Procedure OnStartup (const PgmTitle, CmdLine: String; RunOnce: boolean);
- Var
- Key : String;
- Reg : TRegIniFile;
- Begin
- If RunOnce Then
- Key := 'Once' #0
- Else
- Key := #0;
- Reg := TRegIniFile.create ('');
- Reg.RootKey := HKEY_LOCAL_MACHINE;
- Reg.WriteString ('Software\Microsoft\Windows\CurrentVersion\Run' + Key, ProgTitle, CmdLine);
- Reg.Free
- 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 |
|