Running a program at startup

RaviRanjanKr
Posted by RaviRanjanKr under C# category on | Points: 40 | Views : 1994
You need to use the Registry for running a program at startup. You can use the RegistryKey class that's in the System.Win32 namespace. The following code shows how to do this:
RegistryKey rk = Registry.CurrentUser;
RegistryKey StartupPath;
StartupPath = rk.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
if (StartupPath.GetValue("ProjectName") == null)
{
StartupPath.SetValue("ProjectName", Application.ExecutablePath, RegistryValueKind.ExpandString);
}


Note: RegistryKey is in the System.Win32 namespace, hence don't forget to import it.
I've written same Code Snippet as an answer in CP.

Take a look at my CpAnswer-[http://www.codeproject.com/Answers/123402/Running-a-program-at-startup.aspx#answer1 ]

Comments or Responses

Login to post response