
// <summary> |
/// 开机启动注册 |
/// </summary> |
/// <param name="Started">true 代表写入注册表 false 代表删除注册表</param> |
/// <param name="name">程序的显示名称</param> |
/// <param name="path">程序EXE文件的物理路径</param> |
public void RunWhenStart(bool Started, string name, string path) |
{ |
RegistryKey HKLM = Registry.LocalMachine; |
RegistryKey Run = HKLM.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); |
if (Started == true) |
{ |
try |
{ |
Run.SetValue(name, path); |
HKLM.Close(); |
} |
catch//没有权限会异常 |
{ } |
} |
else |
{ |
try |
{ |
Run.DeleteValue(name); |
HKLM.Close(); |
} |
catch//没有权限会异常 |
{ } |
} |
} |
RunWhenStart(false, "LanMsgServer", Application.StartupPath + "\\LanMsg.exe");//调用代码 |
//判断是否已注册代码 |
RegistryKey loca_chek = Registry.LocalMachine; |
RegistryKey run_Check = loca_chek.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); |
if (run_Check.GetValue("LanMsgServer") != null && run_Check.GetValue("LanMsgServer").ToString().ToLower() != "false") |
{//分别/对应上面的WinForm和false |
menuItemControlServer.Text = "关闭开机启动"; |
} |
else |
{ |
menuItemControlServer.Text = "开机启动"; |
} |




by: 发表于:2018-01-12 14:32:57 顶(0) | 踩(0) 回复
??
回复评论