Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8791037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:47:17+00:00 2026-06-13T22:47:17+00:00

RegistryKey HCU = Registry.CurrentUser.OpenSubKey(Software\\Microsoft\\Windows\\CurrentVersion\\Run, true); foreach (string Programs in HCU.GetValueNames()) { row = dt.NewRow();

  • 0
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 & 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();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:47:18+00:00Added an answer on June 13, 2026 at 10:47 pm

    Answer to Enable or Disable MSconfig startup items with C# window application

    private void uxSave_Click(object sender, EventArgs e)       
    {
    string username = Environment.UserName;
                if (MessageBox.Show("Are you sure to change startup of Item(s)?", "Confirm Startup", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
    
                    for (int j = 0; j < list.Count; j++)
                    {
                        if (j%2 == 0)
                            list1.Add(list[j]);
    
                    }
    
                   foreach (DataGridViewRow ro in uxDgvStartupItems.Rows)
                    {
                        var cellname = (DataGridViewTextBoxCell) ro.Cells[1];
                        string x = Convert.ToString(cellname.Value);
                        foreach (string i in list1)
                        {
                           if (i == x)
                            {
                                string name = i;
                                var sourcee = (DataGridViewTextBoxCell)ro.Cells[2];
                                string source = Convert.ToString(sourcee.Value);
                                var CbxCell = (DataGridViewCheckBoxCell)ro.Cells[0];
    
                                if ((bool)CbxCell.Value == true)
                                {
                                    int flag = 0;
                                    string itemname = "";
                                    RegistryKey HKLM2 =
                                        Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\startupreg",
                                                                         true);
                                    foreach (string Programs in HKLM2.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"));
    
                                                    if (txt == name)
                                                    {
                                                        itemname = Convert.ToString(productKey.GetValue("command"));
                                                        HKLM2.DeleteSubKey(name, false);
                                                        flag = 1;
    
                                                    }
    
                                                }
                                            }
                                        }
                                    }
    
    
                                    RegistryKey HKLM4 =
                                        Registry.LocalMachine.OpenSubKey(
                                            "SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\startupfolder", true);
                                    foreach (string Programs in HKLM4.GetSubKeyNames())
                                    {
    
                                        RegistryKey productKey = HKLM4.OpenSubKey(Programs);
                                        if (productKey != null)
                                        {
                                            foreach (string value in productKey.GetValueNames())
                                            {
                                                if (value == "item")
                                                {
                                                    string txt = Convert.ToString(productKey.GetValue("item"));
    
                                                    if (txt == name)
                                                    {
                                                        HKLM4.DeleteSubKey(Programs, false);
                                                        flag = 2;
                                                    }
    
                                                }
                                            }
                                        }
                                    }
    
    
                                    if (flag == 1)
                                    {
                                        RegistryKey startupKey =
                                            Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
                                        startupKey.SetValue(name, itemname);
                                        startupKey.Close();
                                    }
    
                                    if (flag == 2)
                                    {
                                        string path = "C:\\Users\\" + username + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";
                                        DirectoryInfo di = new DirectoryInfo(targetPath);
                                        FileInfo[] rgFiles = di.GetFiles("*.*");
                                        foreach (FileInfo fi in rgFiles)
                                        {
                                            string itemName = fi.Name;
                                            itemName = itemName.Substring(0, itemName.LastIndexOf('.'));
    
                                            if (itemName == name)
                                            {
    
                                                string sourceFile = Path.Combine(targetPath, name + ".lnk");
                                                string destFile = Path.Combine(path, name + ".lnk");
    
                                                File.Copy(sourceFile, destFile, true);
                                                fi.Delete();
    
                                                fi.Delete();
    
                                            }
    
                                        }
    
                                    }
    
                                }
                                else
                                {
    
                                    if (source == "registry")
                                    {
                                        int flag = 0;
                                        string path = "";
                                        RegistryKey startupKey =
                                            Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
                                                                             true);
                                        foreach (string Programs in startupKey.GetValueNames())
                                        {
                                            if (Programs == name)
                                            {
                                                path = Convert.ToString(startupKey.GetValue(name));
                                                startupKey.DeleteValue(name, false);
                                                startupKey.Close();
                                                flag = 1;
                                            }
    
                                        }
    
                                        if (flag == 0)
                                        {
                                            RegistryKey startupKey1 =
                                                Registry.CurrentUser.OpenSubKey(
                                                    "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                                            foreach (string Programs in startupKey1.GetValueNames())
                                            {
                                                if (Programs == name)
                                                {
                                                    path = Convert.ToString(startupKey1.GetValue(name));
                                                    startupKey1.DeleteValue(name, false);
                                                    startupKey1.Close();
                                                }
    
                                            }
                                        }
    
                                        RegistryKey HKCU =
                                            Registry.LocalMachine.OpenSubKey(
                                                "SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\startupreg", true);
                                        RegistryKey HKCU1 = HKCU.CreateSubKey(name);
                                        HKCU1.SetValue("command", path);
                                        HKCU1.SetValue("hkey", "HKLM");
                                        HKCU1.SetValue("inimapping", "0");
                                        HKCU1.SetValue("item", name);
                                        HKCU1.SetValue("key", "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
                                        HKCU1.SetValue("DAY", DateTime.Now.Day);
                                        HKCU1.SetValue("MONTH", DateTime.Now.Month);
                                        HKCU1.SetValue("YEAR", DateTime.Now.Year);
                                        HKCU1.SetValue("HOUR", DateTime.Now.Hour);
                                        HKCU1.SetValue("MINUTE", DateTime.Now.Minute);
                                        HKCU1.SetValue("SECOND", DateTime.Now.Second);
                                    }
    
                                    if (source == "folder")
                                    {
                                        string path = "C:^Users^" + username + "^AppData^Roaming^Microsoft^Windows^Start Menu^Programs^Startup";
                                        string path1 = "C:\\Users\\" + username + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";
    
                                        DirectoryInfo di =
                                            new DirectoryInfo("C:\\Users\\" + username + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup");
                                        FileInfo[] rgFiles = di.GetFiles("*.*");
                                        foreach (FileInfo fi in rgFiles)
                                        {
                                            string itemName = fi.Name;
                                          itemName = itemName.Substring(0, itemName.LastIndexOf('.'));
    
                                            if (itemName == name)
                                            {
                                                string sourceFile = Path.Combine(path1, name + ".lnk");
                                                string destFile = Path.Combine(targetPath, name + ".lnk");
    
                                                File.Copy(sourceFile, destFile, true);
                                                fi.Delete();
    
                                            }
    
                                        }
    
                                        RegistryKey HKCU =
                                            Registry.LocalMachine.OpenSubKey(
                                                "SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\startupfolder", true);
                                        RegistryKey HKCU1 = HKCU.CreateSubKey(path + "^" + name);
                                        HKCU1.SetValue("path", path1 + "\\" + name);
                                        HKCU1.SetValue("location", path1);
                                        HKCU1.SetValue("item", name);
                                        HKCU1.SetValue("command", path1);
                                        HKCU1.SetValue("backupExtension", ".Startup");
                                        HKCU1.SetValue("backup", "C:\\Windows\\pss\\" + name + ".Startup");
                                        HKCU1.SetValue("DAY", DateTime.Now.Day);
                                        HKCU1.SetValue("MONTH", DateTime.Now.Month);
                                        HKCU1.SetValue("YEAR", DateTime.Now.Year);
                                        HKCU1.SetValue("HOUR", DateTime.Now.Hour);
                                        HKCU1.SetValue("MINUTE", DateTime.Now.Minute);
                                        HKCU1.SetValue("SECOND", DateTime.Now.Second);
    
                                    }
    
                                }
    
                              }
    
                        }
                    }
    
    
                    if (
                        MessageBox.Show("Do you want to restart system to save these changes", "Confirm Restart",
                                        MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        bool privilege;
                        WindowsIdentity identity = WindowsIdentity.GetCurrent();
                        WindowsPrincipal principal = new WindowsPrincipal(identity);
                        privilege = principal.IsInRole(WindowsBuiltInRole.Administrator);
                        if (privilege == true)
                        {
                            Process.Start("ShutDown", "/r");
                        }
                        else
                        {
                            MessageBox.Show("You have not sufficient privileges to restart computer");
                        }
                    }
    
                     list.Clear();
                    list1.Clear();
                }
            }
    
            private void uxDgvStartupItems_CurrentCellDirtyStateChanged(object sender, EventArgs e)
            {
    
                //string[] list = new string[100];
                string name = Convert.ToString(uxDgvStartupItems.Rows[uxDgvStartupItems.CurrentCell.RowIndex].Cells[1].FormattedValue);
                list.Add(name);
    
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

string registryKey = @SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall; using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(registryKey)) { (from a in key.GetSubKeyNames()
The below C++/CLI code returns nullptr to pKey. RegistryKey^ pKey = Microsoft::Win32::Registry::LocalMachine->OpenSubKey(SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\Folders); The below
I am registering my BHO this way: public static string RegistryKeyLocation = Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper
I have created the following registry key (copied through regedit): HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test I would like
I'm trying to read the registry key RPSessionInterval from the subkey HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore in
Here's my code: Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@SOFTWARE\ADM); The registry entry exists on the machine.
Microsoft.Win32.RegistryKey registryPath = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@SOFTWARE\Wow6432Node\Testing); Microsoft.Win32.RegistryKey entryKey = registryPath.OpenSubKey(Entry Point); I have a lot of
When I run the following command, rKey has two values. RegistryKey sqlServer = Registry.LocalMachine.OpenSubKey(
string user = @NT AUTHORITY\NETWORK SERVICE; RegistryKey key = Registry.LocalMachine.OpenSubKey(@SYSTEM\CurrentControlSet\services\eventlog); RegistrySecurity regSec = new
I have the following code: RegistryKey installKey = Registry.LocalMachine.OpenSubKey(installKey); I am running a static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.