2011-05-05 80 views
0

我對C#的工作。最近我TCP服務器 - 客戶端上工作。我寫一個客戶端應用程序。想在客戶端啓動OS。其實我有一個exe文件,想將其激活它的自動啓動當用戶啓動他的電腦。我需要做什麼?謝謝。如果有任何查詢請求。如何自動啓動應用

回答

1

有很多方法,你可以在運行時應用程序的開始。

有關位置的列表。 Check this article

總結他們

Start->Programs->StartUp folder

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run

0

基本上有兩種選擇:

  • 在開始菜單
  • 的啓動文件夾中創建一個快捷方式到你的程序在註冊表中創建的Run關鍵
+0

你會告訴我如何添加註冊表。 – shamim 2011-05-05 08:32:31

+0

我想你可以自己使用谷歌,不是嗎? – 2011-05-05 08:50:21

0

條目窗口自動啓動文件夾可能非常有用。我通常把我的應用程序放在那裏

0

讓您的服務器成爲Windows服務是更好的選擇。這種方式即使沒有人登錄到計算機上,程序也會啓動並運行。 通常,對於需要在OS啓動時運行的服務器應用程序,服務是更好的選擇。

你可以閱讀有關如何在C#中創建一個服務下列article

1

添加下列程序第一頁上的代碼....

public string path; 
    public string fileName; 
    public void GetExeLocation() 
    { 
     path = System.Reflection.Assembly.GetEntryAssembly().Location; // for getting the location of exe file (it can change when you change the location of exe) 
     fileName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; // for getting the name of exe file(it can change when you change the name of exe) 
     StartExeWhenPcStartup(fileName,path); // start the exe autometically when computer is stared. 
    } 

    public void StartExeWhenPcStartup(string filename,string filepath) 
    { 
     Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); 
     key.SetValue(filename, filepath); 
    } 
相關問題