c#设置自启动程序
c#设置自启动程序
using Microsoft.Win32;
if(this.textBox1.Text.Length<1)
{
MessageBox.Show("请首先浏览程序文件选择一个执行程序!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
try
{
string FileName=this.textBox1.Text;
string ShortFileName=FileName.Substring(FileName.LastIndexOf("\\")+1);
//打开子键节点
RegistryKey MyReg=Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",true);
if(MyReg==null)
{//如果子键节点不存在,则创建之
MyReg=Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
}
//在注册表中设置自启动程序
MyReg.SetValue(ShortFileName,FileName);
MessageBox.Show("设置自启动程序操作成功!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(Exception Err)
{
MessageBox.Show("写注册表操作发生错误!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}

浙公网安备 33010602011771号