AutoStartup application - Registry Entry Add / Delete

Auto Start an application when Windows Start.
AutoStart An .EXE while Windows Starts.


RegistryKey rkey;



string strKeyValueInit = "\"" + Application.StartupPath + @"\DocumentUploader.Exe" + "\"";

string strSubKey = @"Software\Microsoft\Windows\CurrentVersion\Run";

try

{

rkey = Registry.CurrentUser.CreateSubKey(strSubKey);

if (rkey.GetValue("DocUp") == null && chkAutoStartWithWindows.CheckState == CheckState.Checked)

{

rkey.SetValue("DocUp", strKeyValueInit);



}



if (rkey.GetValue("DocUp") != null && chkAutoStartWithWindows.CheckState == CheckState.Unchecked)

{

rkey.DeleteValue("DocUp");

}

rkey.Close();



}

catch (Exception ee)

{

MessageBox.Show(ee.Message + " " + ee.StackTrace);

}

No comments: