RegistryKey在Windows窗体应用程序上执行的操作

时间:2013-10-10 10:34:17

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

我有一个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
        {
        }

任何帮助解释它都将受到高度赞赏。

2 个答案:

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

答案 1 :(得分:0)

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