Reputation: 483
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.
Upvotes: 0
Views: 364
Reputation: 1243
It just opens a LocalMachine\Software\Microsoft\Windows\CurrentVersion\Run for writing and sets the app to be lauched on windows start up.
Upvotes: 0
Reputation: 6490
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);
}
Upvotes: 5