如何自动启动应用程序

时间:2011-05-05 08:16:42

标签: c# network-programming registry exe

我在C#上工作。最近我在 Tcp服务器 - 客户端上工作。我写了一个客户端应用程序。当客户端启动操作系统时,它会自动启动。实际上我有一个exe,当用户启动他的计算机时希望它处于活动状态。我需要做什么?Thanks.if有任何查询请问。

5 个答案:

答案 0 :(得分: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

答案 1 :(得分: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);
    }

答案 2 :(得分:0)

基本上,有两种选择:

  • 在开始菜单的“启动”文件夹中创建程序的快捷方式
  • Run密钥
  • 中的注册表中创建一个条目

答案 3 :(得分:0)

Window Autostart文件夹非常有用。我通常把我的应用程序放在那里。

答案 4 :(得分:0)

使您的服务器成为Windows服务是一个更好的选择。这样,即使没有人登录到计算机,您的程序也会启动并运行。 通常,对于需要在OS启动时运行的服务器应用程序,服务是更好的选择。

您可以在以下article

中了解如何使用C#创建服务
相关问题