C#經由過程windows注冊表獲得軟件清單的辦法。本站提示廣大學習愛好者:(C#經由過程windows注冊表獲得軟件清單的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#經由過程windows注冊表獲得軟件清單的辦法正文
本文實例講述了C#經由過程windows注冊表獲得軟件清單的辦法。分享給年夜家供年夜家參考。詳細以下:
foreach (string SoftwareName in Object.SoftwareList())
{
textBox.Text += SoftwareName + Environment.NewLine;
}
////////////////////////////////////////////////////////////////////////
/// <summary>
/// Windows體系獲得軟件列表
/// </summary>
/// <returns>String [] softwareList</returns>
public String [] SoftwareList()
{
String[] softwareList = null;
//靜態數組
ArrayList list = new ArrayList();
try
{
//翻開注冊列表卸載選項
//SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
RegistryKey Key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
if (Key != null)//假如體系制止拜訪則前往null
{
foreach (String SubKeyName in Key.GetSubKeyNames())
{
//翻開對應的軟件稱號
RegistryKey SubKey = Key.OpenSubKey(SubKeyName);
if (SubKey != null)
{
String SoftwareName = SubKey.GetValue("DisplayName", "Nothing").ToString();
//假如沒有取到,則不存入靜態數組
if (SoftwareName != "Nothing")
{
list.Add(SoftwareName);
}
}
}
//強迫轉換成字符串數組,避免被修正數據溢出
softwareList = (string[])list.ToArray(typeof(string));
}
}
catch (Exception err)
{
Console.WriteLine("失足信息:" + err.ToString());
}
return softwareList;
}
願望本文所述對年夜家的C#法式設計有所贊助。