C#實現自動啟動
来源:互联网 发布:python 小程序 编辑:程序博客网 时间:2024/06/08 08:19
private void toolStripMenuItem3_Click(object sender, EventArgs e)
...{
if (autorun == true)
...{
RunWhenStart(false, Application.ProductName, Application.StartupPath + @"" + Application.ProductName+@".exe");
autorun = false;
}
else
...{
RunWhenStart(true, Application.ProductName, Application.StartupPath + @"" + Application.ProductName + @".exe");
autorun = true;
}
Config a = new Config();
a.WriteConfig("autorun", autorun.ToString());
toolStripMenuItem3.Checked = autorun;
}
public static void RunWhenStart(bool Started, string name, string path)
...{
RegistryKey HKLM = Registry.LocalMachine;
RegistryKey Run = HKLM.CreateSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun");
if (Started == true)
...{
try
...{
Run.SetValue(name, path);
HKLM.Close();
}
catch (Exception Err)
...{
MessageBox.Show(Err.Message.ToString(), "友情提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
...{
try
...{
Run.DeleteValue(name);
HKLM.Close();
}
catch (Exception)
...{
MessageBox.Show(Err.Message.ToString(), "友情提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
...{
if (autorun == true)
...{
RunWhenStart(false, Application.ProductName, Application.StartupPath + @"" + Application.ProductName+@".exe");
autorun = false;
}
else
...{
RunWhenStart(true, Application.ProductName, Application.StartupPath + @"" + Application.ProductName + @".exe");
autorun = true;
}
Config a = new Config();
a.WriteConfig("autorun", autorun.ToString());
toolStripMenuItem3.Checked = autorun;
}
public static void RunWhenStart(bool Started, string name, string path)
...{
RegistryKey HKLM = Registry.LocalMachine;
RegistryKey Run = HKLM.CreateSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun");
if (Started == true)
...{
try
...{
Run.SetValue(name, path);
HKLM.Close();
}
catch (Exception Err)
...{
MessageBox.Show(Err.Message.ToString(), "友情提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
...{
try
...{
Run.DeleteValue(name);
HKLM.Close();
}
catch (Exception)
...{
MessageBox.Show(Err.Message.ToString(), "友情提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
- C#實現自動啟動
- C# Winfrom開機自動啟動
- C#自繪多狀態按鈕
- c#程序自启动
- C#自定義直線箭頭大小
- C#开机自启动
- C# 开机自启动
- C#的自开发软件
- C#的自悟
- C# 应用程序自删除
- C#自增和自减
- c# 自绘列表框
- C#反射------转自CSDN
- C#获取自增ID
- c# 自带进制转换
- c# 设置开机自启动
- C#自绘控件外形
- C# WinForm 自绘TreeView
- Windows API一日一练(39)AnimateWindow函数
- 真相,看问题的层次
- 《Windows用户态程序高效排错》 中涉及到的链接
- Xquery实例演示
- X Window研究笔记(8)
- C#實現自動啟動
- 历史上最强大的中国男足成立了
- 转到这里来吧。
- excel表格倒入mysql数据库
- Web 服务最佳实践
- 数据库设计范式
- 有关绘图
- 可以自动发短信了
- String若干问题