2011-05-05 75 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); 
    } 
相关问题