0

I have got work of the maintenance of a windows form application which contains code of windows RegistryKey on Form_Load method of the form..But i have not idea o what work is being performed by RegistryKey code snippet .Here is my code which is puzzling me..

 try
        {
            RegistryKey rkStartUp = Registry.LocalMachine;
            RegistryKey StartupPath;
            StartupPath = rkStartUp.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
            if (StartupPath.GetValue("ABCDXYZ") == null)
            {
                StartupPath.SetValue("ABCDXYZ", Application.ExecutablePath, RegistryValueKind.ExpandString);
            }
        }
        catch
        {
        }

Any help to explain it will be highly appreciated.

pnuts
  • 58,317
  • 11
  • 87
  • 139
vikas
  • 471
  • 3
  • 15
  • 31

2 Answers2

5

This code is just do as in comments

  //gets the local machine registry settings
  RegistryKey rkStartUp = Registry.LocalMachine;
  RegistryKey StartupPath;
  //opens the registry key in which all the windows startup applications are configured
  StartupPath = rkStartUp.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
  //checks if ABDXYZ application is in startup settings, if not exists as startup //app
  if (StartupPath.GetValue("ABCDXYZ") == null)
  {
      //adds the startup app for ABCDXYZ, so that this application will start when windeos starts 
      //next time
      StartupPath.SetValue("ABCDXYZ", Application.ExecutablePath, RegistryValueKind.ExpandString);
  }
Steve
  • 7,171
  • 2
  • 30
  • 52
Rajesh Subramanian
  • 6,400
  • 5
  • 29
  • 42
0

It just opens a LocalMachine\Software\Microsoft\Windows\CurrentVersion\Run for writing and sets the app to be lauched on windows start up.

Vladimir Gondarev
  • 1,243
  • 7
  • 14