当前位置:   article > 正文

【转】C#设置Windows启动项

c# 类库添加window启动项

转自:http://www.csframework.com/archive/2/arc-2-20121231-1969.htm

 

/// <summary> 
/// Windows启动项目管理 
/// </summary> 
public class WinStartItems
{
   const string REG_PATH = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
   
   /// <summary> 
   /// 取程序安装位置 
   /// </summary> 
   /// <param name="registName">键名</param> 
   /// <returns></returns> 
   public static string GetRegistData(string registName)
   {
      string registData;
      RegistryKey key = Registry.LocalMachine.OpenSubKey(REG_PATH, true);
      registData = ConvertEx.ToString(key.GetValue(registName));
      return registData;
   }
   
   /// <summary> 
   /// 取注册表启动项的启动项目名称 
   /// </summary> 
   /// <returns></returns> 
   public static string[] GetRegistName()
   {
      RegistryKey key = Registry.LocalMachine.OpenSubKey(REG_PATH, true);
      return key.GetValueNames();
   }
   
   /// <summary> 
   /// 将程序的开机启动写入注册表 
   /// </summary> 
   /// <param name="runName">启动项目名称</param> 
   /// <param name="starupPath">程序文件名</param> 
   /// <returns></returns> 
   public static bool RegistStartItem(string runName, string starupPath)
   {
      try
      {
         RegistryKey key = Registry.LocalMachine.OpenSubKey(REG_PATH, true);
         key.SetValue(runName, starupPath);
         return true;
      }
      catch
      {
         return false;
      }
   }
   
}

 

转载于:https://www.cnblogs.com/-sylar/p/8383483.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/77211
推荐阅读
相关标签
  

闽ICP备14008679号