0

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

 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
        {
        }

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

4

2 回答 2

5

这段代码就像在评论中一样

  //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);
  }
于 2013-10-10T10:38:13.653 回答
0

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

于 2013-10-10T10:41:55.980 回答