收集電腦上安裝的軟件列表,收集電腦安裝列表
公司的IT工程師某一天找我聊天,說有沒有一個程序能夠統計電腦上安裝的軟件,公司采用的是域控,然後把這個軟件放在域控的組策略裡面,設置一番,只要登錄域控的時候自動運行一遍,然後把采集的信息寫入共享目錄,這樣就不用一台一台的統計了。
當時一想就直接用C#寫了一個控制台程序。代碼如下:

![]()
static void Main(string[] args)
{
string path = @"\\192.168.10.251\\hard_info\\";
StringBuilder proinfo = new StringBuilder();
string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
{
foreach (string skName in rk.GetSubKeyNames())
{
using (RegistryKey sk = rk.OpenSubKey(skName))
{
try
{
var displayName = sk.GetValue("DisplayName");
if (displayName != null)
{
proinfo.AppendLine(displayName.ToString());
}
}
catch
{
}
}
}
}
File.WriteAllText(path + Dns.GetHostName() + ".txt", proinfo.ToString());
Environment.Exit(0);
}
View Code
運行以後,是能統計出來,但是少了很多軟件,只有一部分,網上查詢一番,發現要區分64位操作系統和32位系統,還要區分是LocalMachine還是CurrentUser
針對x86系統
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
針對x64系統
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
HKEY_CURRENT_USER\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
根據以上,改進以後代碼如下:

![]()
static void Main(string[] args)
{
string path = @"\\192.168.10.251\\hard_info\\";
StringBuilder proinfo = new StringBuilder();
proinfo = ShowAllSoftwaresName();
File.WriteAllText(path + Dns.GetHostName() + ".txt", proinfo.ToString());
Environment.Exit(0);
}
public static StringBuilder DisplayInstalledApps(RegistryKey key)
{
StringBuilder result = new StringBuilder();
string displayName;
if (key != null)
{
foreach (String keyName in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(keyName);
displayName = subkey.GetValue("DisplayName") as string;
if (!string.IsNullOrEmpty(displayName))
{
result.AppendLine(displayName);
}
}
}
return result;
}
public static StringBuilder ShowAllSoftwaresName()
{
StringBuilder proinfo = new StringBuilder();
RegistryKey key;
// search in: CurrentUser
key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
proinfo.Append(DisplayInstalledApps(key));
// search in: LocalMachine_32
key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
proinfo.Append(DisplayInstalledApps(key));
// search in: CurrentUser_64
key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
proinfo.Append(DisplayInstalledApps(key));
// search in: LocalMachine_64
key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
proinfo.Append(DisplayInstalledApps(key));
return proinfo;
}
View Code
運行以後,全部采集了電腦安裝的軟件。
發給IT工程師後,反饋:有部分電腦運行不了。。。xp系統不支持。。。系統默認沒安裝framework

最後和IT工程師商議後,可以使用VBS,以前也寫過VBS,網上找找資料就寫了一個,完美解決了。
附件為vbs腳本:vbs獲取軟件列表.zip
參考資料:
VBScript:檢查目標計算機軟件列表
PowerShell快速高效地獲取安裝的軟件列表
Uninstall Registry Key