softlist

softlist

前段时间看到 @3gstudent 用来提取软件列表的powershell脚本,于是就写了个c#版本的,bug不少,不过勉强够用,在x64上提取不全,过段时间再改进一下

源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using 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();
}
}
}