Frage

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.

War es hilfreich?

Lösung

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);
  }

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top