110,539
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 确定 按钮 事件(是否设置为开机自动启动)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button4_Click(object sender, EventArgs e)
{
if (autoCheck.Checked == true)
{
//获取程序执行路径..
string starupPath = Application.ExecutablePath;
//class Micosoft.Win32.RegistryKey. 表示Window注册表中项级节点,此类是注册表装.
RegistryKey loca = Registry.LocalMachine;
RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
try
{
//SetValue:存储值的名称
run.SetValue("qidong", starupPath);
/// MessageBox.Show("已启用开机运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
loca.Close();
}
catch (Exception ee)
{
MessageBox.Show(ee.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
// MessageBox.Show("没有选中");
//获取程序执行路径..
string starupPath = Application.ExecutablePath;
//class Micosoft.Win32.RegistryKey. 表示Window注册表中项级节点,此类是注册表装.
RegistryKey loca = Registry.LocalMachine;
RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
try
{
//SetValue:存储值的名称
run.DeleteValue("qidong");
MessageBox.Show("已停止开机运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
loca.Close();
}
catch (Exception ee)
{
MessageBox.Show(ee.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}