【转】C#设置Windows启动项

2021-02-17 11:18

阅读:688

标签:ons   tar   run   class   current   gpo   oca   注册表   items   

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

 

///  
/// Windows启动项目管理 
///  
public class WinStartItems
{
   const string REG_PATH = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
   
   ///  
   /// 取程序安装位置 
   ///  
   /// 键名 
   ///  
   public static string GetRegistData(string registName)
   {
      string registData;
      RegistryKey key = Registry.LocalMachine.OpenSubKey(REG_PATH, true);
      registData = ConvertEx.ToString(key.GetValue(registName));
      return registData;
   }
   
   ///  
   /// 取注册表启动项的启动项目名称 
   ///  
   ///  
   public static string[] GetRegistName()
   {
      RegistryKey key = Registry.LocalMachine.OpenSubKey(REG_PATH, true);
      return key.GetValueNames();
   }
   
   ///  
   /// 将程序的开机启动写入注册表 
   ///  
   /// 启动项目名称 
   /// 程序文件名 
   ///  
   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;
      }
   }
   
}

 

【转】C#设置Windows启动项

标签:ons   tar   run   class   current   gpo   oca   注册表   items   

原文地址:https://www.cnblogs.com/-sylar/p/8383483.html


评论


亲,登录后才可以留言!