softlist 发表于 2018-03-12 softlist前段时间看到 @3gstudent 用来提取软件列表的powershell脚本,于是就写了个c#版本的,bug不少,不过勉强够用,在x64上提取不全,过段时间再改进一下 源码123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114using System;using System.Collections.Generic;using System.Text;using System.Management;using Microsoft;using Microsoft.Win32;namespace softlist{ class Program { private static string OSBit() { try { ConnectionOptions oConn = new ConnectionOptions(); System.Management.ManagementScope managementScope = new System.Management.ManagementScope("\\\\localhost", oConn); System.Management.ObjectQuery objectQuery = new System.Management.ObjectQuery("select AddressWidth from Win32_Processor"); ManagementObjectSearcher moSearcher = new ManagementObjectSearcher(managementScope, objectQuery); ManagementObjectCollection moReturnCollection = null; string addressWidth = null; moReturnCollection = moSearcher.Get(); foreach (ManagementObject oReturn in moReturnCollection) { addressWidth = oReturn["AddressWidth"].ToString(); } return addressWidth; } catch { return "获取错误"; } } static void Main(string[] args) { //string a = softlist.Program.OSBit(); if (softlist.Program.OSBit() == "32") { using (RegistryKey key32 = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", false)) { if (key32 != null) { foreach (string keyName in key32.GetSubKeyNames()) { using (RegistryKey key2 = key32.OpenSubKey(keyName, false)) { if (key2 != null) { string softwareName = key2.GetValue("DisplayName", "").ToString(); string installLocation = key2.GetValue("InstallLocation", "").ToString(); if (!string.IsNullOrEmpty(installLocation)) { Console.WriteLine(string.Format("软件名:{0} --- 安装路径:{1}\r", softwareName, installLocation)); } } } } } } } else { using (RegistryKey key64 = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\", false)) { if (key64 != null) { foreach (string keyName in key64.GetSubKeyNames()) { using (RegistryKey key2 = key64.OpenSubKey(keyName, false)) { if (key2 != null) { string softwareName = key2.GetValue("DisplayName", "").ToString(); string installLocation =key2.GetValue("InstallLocation", "").ToString(); if (!string.IsNullOrEmpty(installLocation)) { Console.WriteLine(string.Format("软件名:{0} --- 安装路径:{1}\r",softwareName, installLocation)); } } } } } Console.WriteLine("\r\n--------------------------------------个分割线---------------------------------------\r\n"); using (RegistryKey key32 = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\", false)) { if (key32 != null) { foreach (string keyName in key32.GetSubKeyNames()) { using (RegistryKey key2 = key32.OpenSubKey(keyName, false)) { if (key2 != null) { string softwareName = key2.GetValue("DisplayName", "").ToString(); string installLocation = key2.GetValue("InstallLocation", "").ToString(); if (!string.IsNullOrEmpty(installLocation)) { Console.WriteLine(string.Format("软件名:{0} --- 安装路径:{1}\r", softwareName, installLocation)); } } } } } } } } Console.ReadLine(); } }}