2011-09-15 112 views
1

所以,程序從Windows開始? c#

我已經建立了一個winforms,只是打開一個新的程序。

即在WinForm的代碼是這樣的:(如果有人需要)

Process a; 

Process a = Process.Start("notepad.exe"); 

BUT。

我需要知道如何才能讓程序以Windows啓動啓動。像Skype,或任何其他程序。

所以。

  1. 我建立了一個winforms應用程序。
  2. 我做了一個啓動過程。
  3. 現在我需要幫助做到這一點,該程序將打開窗口。

唯一重要的是,該程序將允許我選擇我希望她開始與Windows或不。所以,如果有人給我功能,請給我開\關功能。感謝ALLOT!

+1

快速Google揭示http://simpcode.blogspot.com/2008/07/c-set-and-unset-auto-start-for-windows.html – Scott

+1

這應該是您的應用程序安裝的一部分。 http://www.bleepingcomputer.com/tutorials/tutorial44.html –

+0

[C#autostart自動添加應用程序到啓動文件夾]的可能的重複(http://stackoverflow.com/questions/4247439/c-autostart-automatically-add-應用程序到啓動文件夾) –

回答

11

如果要在Windows啓動時自動啓動應用程序,則必須在Windows註冊表中註冊它。

你需要一個新值添加到以下注冊表項:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run 

將開始爲當前用戶的應用程序

或關鍵

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run 

這將啓動適用於所有用戶

以下示例將啓動應用爲當前用戶:

var path = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; 
RegistryKey key = Registry.CurrentUser.OpenSubKey(path, true); 
key.SetValue("MyApplication", Application.ExecutablePath.ToString()); 

只是

RegistryKey key = Registry.LocalMachine.OpenSubKey(path, true); 

更換行第二行,如果你想自動啓動在Windows啓動時所有的用戶應用程序。

如果您想禁用此功能,以免應用程序自動啓動,請刪除註冊表值。

var path = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; 
RegistryKey key = Registry.CurrentUser.OpenSubKey(path, true); 
key.DeleteValue("MyApplication", false); 
0

由於您要求運行NOTEPAD.EXE,您可以通過將它的圖標放入啓動Windows文件夾中直接運行它。