注册表键在 Windows 窗体应用程序上的作用



我有一个Windows表单应用程序的维护工作,该应用程序包含表单方法上的Windows RegistryKey代码Form_Load。但是我不知道注册表密钥代码片段正在执行什么工作。这是我的代码,让我感到困惑。

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

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

这段代码就像在注释中一样做

  //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(@"SoftwareMicrosoftWindowsCurrentVersionRun", 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);
  }

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

相关内容

  • 没有找到相关文章

最新更新