• Log in or sign up for an account here: https://www.sythe.org/login

Trouble writing to the registry

Status
Not open for further replies.

ScubaSteve7

Member
Joined
Dec 1, 2010
Sythe Gold
0
Messages
35
So this is my attempt at writing to the registry for my program to open up when windows starts.

Code:
RegistryKey App = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsft\\Windows\\CurrentVersion\\Run", true);

                if (App.GetValue("MyApp") == null)
                {
                    App.DeleteValue("MyApp", false);
                    App.SetValue("MyApp", System.Reflection.Assembly.GetExecutingAssembly().Location.ToString());
                    Console.WriteLine("Program runs at startup.");
                }
                else
                    Console.WriteLine("Program runs at startup.");

When trying to write the executable path to the registry, I get his error:
Code:
System.NullReferenceException: Object reference not set to an instance of an object.
   at App.Program.Main(String[] args) in C:\Users\Steve\Desktop\csLK\csLK\
Program.cs:line 41

Any ideas as to what I'm doing wrong? I'm a newb.
 
Don't know .NET too well, but here's my guess:
App.DeleteValue("MyApp", false);

Why are you deleting an object which you've already determined doesn't exist? Shouldn't it be CreateValue first?
 
Ahh yea I do already check for that, I had thrown in the delete in some attempt to try to make it work lol.
Still having trouble.
 
Le Monkey
PHP Shit Show 2k26
Potamus
Prove it!
Sythe Awards 2011 Winner
Tier 1 Prizebox
Tortoise Penis
Trole
UWotM8?
Wait, do you not have an Archer rank?
Create the value before setting it.
 
I thought that's what i was doing by doing:
RegistryKey App = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsft\\Windows\\CurrentVersion\\Run", true);
 
Le Monkey
PHP Shit Show 2k26
Potamus
Prove it!
Sythe Awards 2011 Winner
Tier 1 Prizebox
Tortoise Penis
Trole
UWotM8?
Wait, do you not have an Archer rank?
Once you open the subkey, create a new value in it.
 
Le Monkey
PHP Shit Show 2k26
Potamus
Prove it!
Sythe Awards 2011 Winner
Tier 1 Prizebox
Tortoise Penis
Trole
UWotM8?
Wait, do you not have an Archer rank?
Oh wait, my bad, there's no CreateValue thing in .NET.

SOFTWARE\\Microsft\\Windows\\CurrentVersion\\Run

Spell Microsoft right ;)
 
Man all that confusion... attributed to a spelling mistake, Thanks for the help SMR it's working.
 
Le Monkey
PHP Shit Show 2k26
Potamus
Prove it!
Sythe Awards 2011 Winner
Tier 1 Prizebox
Tortoise Penis
Trole
UWotM8?
Wait, do you not have an Archer rank?
Haha, mind if I lock the thread now :P
 
Status
Not open for further replies.
Runescape Gamblingrunescape gambling
Back
Top