title: Enable/Disable MSCONFIG Startup Items with C#
body: <pre><code>RegistryKey HCU = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
          foreach (string Programs in HCU.GetValueNames())
          {
              row = dt.NewRow();
              row["Item Name"] = Programs;
              dt.Rows.Add(row);
          }
  
          RegistryKey HLM = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
          foreach (string Programs in HLM.GetValueNames())
          {
  
              row = dt.NewRow();
              row["Item Name"] = Programs;
              dt.Rows.Add(row);
          }
  
          DirectoryInfo di = new DirectoryInfo(@"C:\Users\DEV2\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup");
          FileInfo[] rgFiles = di.GetFiles("*.*");
          foreach (FileInfo fi in rgFiles)
          {
              if ((fi.Attributes &amp; FileAttributes.Hidden) != FileAttributes.Hidden)
              {
                  row = dt.NewRow();
                  row["Item Name"] = fi.Name;
                  dt.Rows.Add(row);
              }
  
          }
  
  
          RegistryKey HKLM = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\startupreg", true);
          foreach (string Programs in HKLM.GetSubKeyNames())
          {
              // string GetFilePath = HKCU.GetValue(Programs).ToString();
  
              row = dt.NewRow();
              row["Item Name"] = Programs;
             // row["Location"] = "HKLM\\SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\startupreg";
              dt.Rows.Add(row);
          }
  
          RegistryKey HKLM2 = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\startupfolder", true);
          foreach (string Programs in HKLM2.GetSubKeyNames())
          {
  
              RegistryKey productKey = HKLM2.OpenSubKey(Programs);
              if (productKey != null)
              {
                  foreach (string value in productKey.GetValueNames())
                  {
                      if (value == "item")
                      {
                          row = dt.NewRow();
                          row["Item Name"] = Convert.ToString(productKey.GetValue("item"));
                          // row["Location"] = "HKLM\\SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\startupreg";
                          dt.Rows.Add(row);
                      }
                  }
              }
          }
  
          uxDgvStartupItems.DataSource = dt;
  
          DataGridViewColumn column = uxDgvStartupItems.Columns["Item Name"];
          column.Width = 600;
  
          foreach (DataGridViewRow ro in uxDgvStartupItems.Rows)
          {
  
                  DataGridViewCheckBoxCell ch1 = (DataGridViewCheckBoxCell)ro.Cells[0];
                  ch1.Value = true;
  
          }
  
  
          RegistryKey HKCU3 = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\startupfolder", true);
          foreach (string Programs in HKCU3.GetSubKeyNames())
          {
  
                 RegistryKey productKey = HKLM2.OpenSubKey(Programs);
                 if (productKey != null)
                 {
                     foreach (string value in productKey.GetValueNames())
                     {
                         if (value == "item")
                         {
                             string txt = Convert.ToString(productKey.GetValue("item"));
  
                             foreach (DataGridViewRow ro in uxDgvStartupItems.Rows)
                             {
                                 string txt1 = ro.Cells[1].Value.ToString();
                                 if (txt == txt1)
                                 {
                                     var ch2 = (DataGridViewCheckBoxCell) ro.Cells[0];
                                     ch2.Value = false;
                                 }
                             }
                         }
                     }
                 }
          }
  
  
          RegistryKey HKCU1 = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\startupreg", true);
          foreach (string Programs in HKCU1.GetSubKeyNames())
          {
              string txt = Programs;
  
              foreach (DataGridViewRow ro in uxDgvStartupItems.Rows)
              {
                  string txt1 = ro.Cells[1].Value.ToString();
                  //var txt1 = uxDgvStartupItems.Rows[uxDgvStartupItems.CurrentCell.RowIndex].Cells[1].FormattedValue.ToString();
                  if (txt == txt1)
                  {
                      var ch2 = (DataGridViewCheckBoxCell)ro.Cells[0];
                      ch2.Value = false;
                  }
              }
          }
          HKCU1.Close();
  </code></pre>