首页 > Windows开发 > 详细

【转】C#设置Windows启动项

时间:2018-01-30 10:13:28      阅读:314      评论:0      收藏:0      [点我收藏+]

转自: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;
      }
   }
   
}

 

【转】C#设置Windows启动项

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!