using Microsoft.Win32;
private void Form1_Load(object sender, EventArgs e)
{
//获取程序执行路径..
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("WinForm", starupPath);
MessageBox.Show("注册表添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
loca.Close();
}
catch (Exception ee)
{
MessageBox.Show(ee.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//删除开机启动
以上代码写一遍,不同的是:
把 run.SetValue("WinForm", starupPath);
换乘 run.DeleteValue("WinForm");//用于删除键值对。
浙公网安备 33010602011771号