bestlong 怕失憶論壇

 

 

搜索
bestlong 怕失憶論壇 論壇 Delphi 如何讓程式在每次開機時都執行或只執行一次 ...
查看: 4940|回復: 0
go

如何讓程式在每次開機時都執行或只執行一次 [複製鏈接]

Rank: 9Rank: 9Rank: 9

1#
發表於 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
我是雪龍
http://blog.bestlong.idv.tw
http://www.bestlong.idv.tw
‹ 上一主題|下一主題

Archiver|怕失憶論壇

GMT+8, 2025-5-3 00:28 , Processed in 0.015285 second(s), 11 queries .

Powered by Discuz! X1.5

© 2001-2010 Comsenz Inc.