Mitchell  Kemp

Mitchell Kemp

  • NA
  • 1
  • 1.9k

Trouble with checking registry keys

Feb 17 2012 12:13 AM
Hi,
I am trying to check for a registry key from within a wpf application and then create a key if necessary but the code im using is constantly returning a null value for any key i try to open.

Any Pointers will be much appreciated.

 bool chkRun;

  RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

        public MainWindow()
        {
            InitializeComponent();

            if (rkApp.GetValue("TellMeIP") == null)            
            {                
                // The value doesn't exist, the application is not set to run at startup                
                chkRun = false;
                MessageBox.Show("NULL");
            }            
            else            
            {                
                // The value exists, the application is set to run at startup                
                chkRun = true;            
            }
           
       
            if (chkRun == false)            
            {                
                // Add the value in the registry so that the application runs at startup
                rkApp.CreateSubKey("TellMeIP");
                rkApp.SetValue("TellMeIP", System.Reflection.Assembly.GetExecutingAssembly().Location.ToString());            
            }            
            else            
            {                
                   
            }


 }


Attachment: registry key.zip

Answers (2)