Start up with Windows
April 11, 2009
Twitter's a new exciting social media. And guess what, I'm quite active on it. Follow me on Twitter to get the latest links and updates.
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