C#设置开机启动项代码
/要触发的事件,一般是checkBox1的CheckedChanged事件private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked) //设置开机自启动
{
MessageBox.Show ("设置开机自启动,需要修改注册表","提示");// hovertree.com
string path = Application.ExecutablePath;
RegistryKey rk = Registry.LocalMachine;
RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
rk2.SetValue("JcShutdown", path);
rk2.Close();
rk.Close();
}
else //取消开机自启动
{
MessageBox.Show ("取消开机自启动,需要修改注册表","提示");
string path = Application.ExecutablePath;
RegistryKey rk = Registry.LocalMachine;
RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
rk2.DeleteValue("JcShutdown", false);
rk2.Close();
rk.Close();
}
}
装个B就跑,真刺激
页:
[1]