-
C# 将程序添加到启动项 (写入注册表),及从启动项中删除
- #region 将程序添加到启动项
-
-
-
- public static void SetRegistryApp()
- {
- try
- {
- Microsoft.Win32.RegistryKey Reg;
- string ShortFileName = Application.ProductName;
- Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", true);
- if (Reg == null)
- {
- Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run");
- }
- Reg.SetValue(ShortFileName, Application.ExecutablePath);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- #endregion
-
- #region 将程序从启动项中删除
-
-
-
- public static bool DeleteRegisterApp()
- {
- string ShortFileName = Application.ProductName;
-
- try
- {
- Microsoft.Win32.RegistryKey Reg;
- Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", true);
- if (Reg == null)
- {
- Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run");
- }
- Reg.DeleteValue(ShortFileName, false);
- }
- catch (Exception ex)
- {
- return false;
- }
-
- return true;
- }
- #endregion
-
-
-
-
-
- public static bool CheckExistRegisterApp()
- {
- string ShortFileName = Application.ProductName;
- bool bResult = false;
-
- try
- {
- Microsoft.Win32.RegistryKey Reg;
- Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", true);
- if (Reg == null)
- {
- Reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run");
- }
-
- foreach (string s in Reg.GetValueNames())
- {
- if (s.Equals(ShortFileName))
- {
- bResult = true;
- break;
- }
- }
- }
- catch (Exception ex)
- {
- return false;
- }
-
- return bResult;
- }
-
相关阅读:
10.19JDBC之DBCP连接池的使用
计时器Timer介绍
Silverlight3.0 起步(一)——环境
javascript 类
RhinoMock入门(6)——安装结果和约束
RhinoMock入门(4)——次序和委托
javascript 表达式、括号、常用函数和jquery库怎么样实现的分析
CSP加密服务(一)
RhinoMock入门(5)——属性,方法和方法选项
RhinoMock入门(7)——Do,With和Recordplayback
-
原文地址:https://www.cnblogs.com/2260827114com/p/6410728.html
Copyright © 2020-2023
润新知