如何在Windows啟動後自動執行特定程式

  • 4609
  • 0

摘要:如何在Windows啟動後自動執行特定程式

參考文章

http://oreilly.com/pub/a/oreilly/windows/ron/startup_0401.html

該文章中提到幾種方式(1) Autoexec.bat (2) Win.ini (3) "啟動" (4)Registry

因為我的程式只需要在特定狀況下才需要在window啟動後自動執行,所以我選擇Resigtry的方式。

由程式內部來控制何時該自動執行。

該文中提到以下幾個方式

HKCU\Software\Microsoft\Windows\CurrentVersion\Run

Launches a program automatically when a particular user logs in. This key is used when you always want to launch a program when a particular user is using a system.

HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce

Launches a program the next time the user logs in and removes its value entry from the registry. This key is typically used by installation programs.

HKLM\Software\Microsoft\Windows\CurrentVersion\Run

Launches a program automatically at system startup. This key is used when you always want to launch a program on a particular system.

HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce

Launches a program the next time the system starts and removes its value entry from the registry. This key is typically used by installation programs.

HKLM\Software\Microsoft\Windows\CurrentVersion\RunServices

Launches a service (a standard NT service or a background process) automatically at startup. An example of a service is a Web server such as Microsoft Internet Information Server.

HKLM\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce
另外還有
HKLM\Software\Microsoft\Windows\CurrentVersion\RunEx and HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnceEx
可參考Microsoft KnowledgeBase article Q232509, "Syntax and Flags Used for the RunOnceEx and RunEx Keys."
依我的需求,應該只會用到
HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce
接下來就只要將Key及Value寫到該位置即可了。
Key:任意名稱
Value:要執行的程式的完整路徑及檔名。
而寫入的方式可以呼叫.Net提供的類別(Microsoft.Win32.Registry.LocalMachine)即可,或參考該文章的方式(利用VB Script)
 
以上。

============ 以下是簽名檔 ============

一個小小螺絲釘。

第一次建立Blog,希望以後能慢慢充實它。

Howard