C# 设置开机自启动

发布时间:2009年08月21日      浏览次数:886 次
private void btn_save_Click(object sender, System.EventArgs e)
{
//设置开机自启动---------------------------------
if (auto_start.Checked)
{
string path = Application.ExecutablePath;
Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
rk2.SetValue("MySoft", path);
rk2.Close();
rk.Close();
}
else //取消开机自启动
{
string path = Application.ExecutablePath;
Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
rk2.DeleteValue("MySoft", false);
rk2.Close();
rk.Close();
}
}
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!