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

本文关键字:应用程序 程序上 作用 应用 窗体 Windows 注册表 | 更新日期: 2023-09-27 18:34:48

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

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

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

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

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

  //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);
  }

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