【问题标题】:What RegistryKey does on Windows Form ApplicationRegistryKey 在 Windows 窗体应用程序上的作用
【发布时间】:2013-10-10 10:34:16
【问题描述】:

我已经完成了 Windows 窗体应用程序的维护工作,该应用程序包含窗体的 Form_Load 方法上的 windows RegistryKey 代码。但我不知道 RegistryKey 代码 sn-p 正在执行什么工作。这是我的让我困惑的代码..

 try
        {
            RegistryKey rkStartUp = Registry.LocalMachine;
            RegistryKey StartupPath;
            StartupPath = rkStartUp.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
            if (StartupPath.GetValue("ABCDXYZ") == null)
            {
                StartupPath.SetValue("ABCDXYZ", Application.ExecutablePath, RegistryValueKind.ExpandString);
            }
        }
        catch
        {
        }

任何解释它的帮助将不胜感激。

【问题讨论】:

    标签: c# registry windows-api-code-pack


    【解决方案1】:

    这段代码和 cmets 一样

      //gets the local machine registry settings
      RegistryKey rkStartUp = Registry.LocalMachine;
      RegistryKey StartupPath;
      //opens the registry key in which all the windows startup applications are configured
      StartupPath = rkStartUp.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
      //checks if ABDXYZ application is in startup settings, if not exists as startup //app
      if (StartupPath.GetValue("ABCDXYZ") == null)
      {
          //adds the startup app for ABCDXYZ, so that this application will start when windeos starts 
          //next time
          StartupPath.SetValue("ABCDXYZ", Application.ExecutablePath, RegistryValueKind.ExpandString);
      }
    

    【讨论】:

      【解决方案2】:

      它只是打开一个 LocalMachine\Software\Microsoft\Windows\CurrentVersion\Run 进行写入并将应用程序设置为在 Windows 启动时启动。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多