您的位置:首页 > 编程语言 > C#

C#用注册表开机自动启动某某软件

2016-01-06 10:10 309 查看
代码如下:

public static void chkAutoRun(bool isRun)
{
if (isRun)//开机自动启动
{
try
{
RegistryKey runKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
runKey.SetValue("AutoRun.exe", System.Windows.Forms.Application.ExecutablePath);
runKey.Close();
this.Text = "注册表修改自启(已开启)";
}
catch (IOException ie)
{
MessageBox.Show(ie.Message);
}
}
else  //不开机自动启动注册表信息删除
{
RegistryKey software = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
string[] aimnames = software.GetValueNames();
foreach (string aimKey in aimnames)
{
if (aimKey.Equals("AutoRun.exe"))
{
software.DeleteValue("AutoRun.exe");
software.Close();
break;
}
}
this.Text = "注册表修改自启(已关闭)";
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: