本文實例講述了C#實現讀取注冊表監控當前操作系統已安裝軟件變化的方法。分享給大家供大家參考。具體實現方法如下:
private static HybridDictionary GetSoftName(){ string strSoftName = string.Empty; HybridDictionary hdSoftName = new HybridDictionary(); /*對注冊表節點"Software/Microsoft/Windows/CurrentVersion/Uninstall"下的內容進行操作。 RegistryKey Registry 為注冊表操作類*/ using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software/Microsoft/Windows/CurrentVersion/Uninstall", false)) { if (key != null) { foreach (string keyName in key.GetSubKeyNames()) { using (RegistryKey key2 = key.OpenSubKey(keyName, false)) { if (key2 != null) { string softwareName = Convert.ToString(key2.GetValue("DisplayName"));//獲取DisplayName,如存在值,則系統中安裝有該軟件 //string installLocation = key2.GetValue("InstallLocation", "").ToString();//軟件安裝路徑 if (!string.IsNullOrEmpty(softwareName)) { if (!hdSoftName.Contains(softwareName)) { hdSoftName.Add(softwareName, string.Empty);//將軟件名作為集合的key } } } } } } } return hdSoftName;}
希望本文所述對大家的C#程序設計有所幫助。
新聞熱點
疑難解答