bestlong 怕失憶論壇
標題:
如何讓程式在每次開機時都執行或只執行一次
[打印本頁]
作者:
bestlong
時間:
2007-12-14 08:20
標題:
如何讓程式在每次開機時都執行或只執行一次
有的時候會希望程式在電腦開機時就執行或只執行一次,可以用設定系統機碼的方式來處理
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
歡迎光臨 bestlong 怕失憶論壇 (http://www.bestlong.idv.tw/)
Powered by Discuz! X1.5