© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
1 reply
Alex

Adding program to Local Machine Registry

Hey there! I've been trying to add a program to the local machine registry
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
so that it runs on boot, but this seemingly isn't working. I have administrator privileges.

// Get the key to be added to the Windows Registry
            RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
            string bootScriptFilepath = Path.Combine(serverSection.AddSection(ScriptsSectionName).SectionFullPath, BootScriptName);

            if (serverSection.GetFirstDocumentNamed("boot.bat") == null)
            {
                // Create the .bat file to be added to the Windows Registry
                string[] command = BuildStringForStartupRegistryCommand(serverSection.SimpleName).Split('\n');
                FileUtils.DumpToFile(bootScriptFilepath, command.ToList().Select(s => s.Trim()).ToList());
            }

            // Add the key to the Windows Registry if it doesn't already exist
            if (key != null && !IsServerInRegistry(serverSection))
            {
                key.SetValue("Glowberry-" + serverSection.SimpleName, bootScriptFilepath);
                key.Flush();
                key.Close();
                return true;
            }

            return false;
// Get the key to be added to the Windows Registry
            RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
            string bootScriptFilepath = Path.Combine(serverSection.AddSection(ScriptsSectionName).SectionFullPath, BootScriptName);

            if (serverSection.GetFirstDocumentNamed("boot.bat") == null)
            {
                // Create the .bat file to be added to the Windows Registry
                string[] command = BuildStringForStartupRegistryCommand(serverSection.SimpleName).Split('\n');
                FileUtils.DumpToFile(bootScriptFilepath, command.ToList().Select(s => s.Trim()).ToList());
            }

            // Add the key to the Windows Registry if it doesn't already exist
            if (key != null && !IsServerInRegistry(serverSection))
            {
                key.SetValue("Glowberry-" + serverSection.SimpleName, bootScriptFilepath);
                key.Flush();
                key.Close();
                return true;
            }

            return false;


That's the code I'm using; There's more that checks if it is in and stuff, and whilst
key.GetValue()
key.GetValue()
returns an actual value and not null, the entry isn't added to regedit, and my program doesn't actually start on boot. Help?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Adding Polymorphism to a program
C#CC# / help
3y ago
✅ Little help adding music to a program
C#CC# / help
2y ago
✅ Testing GitHub webhooks on my local machine
C#CC# / help
3y ago
Local machine refuses to connect to an ASP.NET Core Web API container
C#CC# / help
2y ago