Start up with Windows
April 11, 2009
There is no reason we shouldn't share our knowledge and experience. Please send me an article about IT, I will post it on my website, sure with a link back to your website. [More]
Allow user to set the application start up with Windows.
Require a checkbox to switch between startup or not.
Microsoft.Win32.RegistryKey StartUpRKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
string AppKeyName = "ShrinkerApp";
public void StartUpWithWindow()
{
if(!StartedUp)
StartUpRKey.SetValue(AppKeyName, Application.ExecutablePath.ToString());
}
public void StopStartUp()
{
if(StartedUp)
StartUpRKey.DeleteValue(AppKeyName, false);
}
public bool StartedUp
{
get
{
return (StartUpRKey.GetValue(AppKeyName) != null);
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
StartUpWithWindow();
}
else
{
StopStartUp();
}
}
public FrmMain()
{
InitializeComponent();
if (StartedUp)
{
checkBox1.Checked = true;
}
}
Leave a Reply