亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#通過windows注冊表獲取軟件清單的方法

 更新時(shí)間:2015年07月15日 15:11:29   作者:搶小孩糖吃  
這篇文章主要介紹了C#通過windows注冊表獲取軟件清單的方法,涉及C#針對注冊表的訪問讀取與遍歷操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了C#通過windows注冊表獲取軟件清單的方法。分享給大家供大家參考。具體如下:

foreach (string SoftwareName in Object.SoftwareList())
{
  textBox.Text += SoftwareName + Environment.NewLine;
}
////////////////////////////////////////////////////////////////////////
/// <summary>
/// Windows系統(tǒng)獲取軟件列表
/// </summary>
/// <returns>String [] softwareList</returns>
public String [] SoftwareList()
{
 String[] softwareList = null;
 //動態(tài)數(shù)組
 ArrayList list = new ArrayList();
 try
 {
  //打開注冊列表卸載選項(xiàng)
  //SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
  RegistryKey Key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
  if (Key != null)//如果系統(tǒng)禁止訪問則返回null
  {
   foreach (String SubKeyName in Key.GetSubKeyNames())
   {
    //打開對應(yīng)的軟件名稱
    RegistryKey SubKey = Key.OpenSubKey(SubKeyName);
    if (SubKey != null)
    {
     String SoftwareName = SubKey.GetValue("DisplayName", "Nothing").ToString();
     //如果沒有取到,則不存入動態(tài)數(shù)組
     if (SoftwareName != "Nothing")
     {
      list.Add(SoftwareName);
     }
    }
   }
   //強(qiáng)制轉(zhuǎn)換成字符串?dāng)?shù)組,防止被修改數(shù)據(jù)溢出
   softwareList = (string[])list.ToArray(typeof(string));
  }
 }
 catch (Exception err)
 {
  Console.WriteLine("出錯(cuò)信息:" + err.ToString());
 }
 return softwareList;
}

希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論