如何用VBS脚本收集远程计算机或本地计算机安装的软件
使用VBS脚本可收集域内远程或本地计算机的软件及Windows版本信息,结果保存为以计算机名命名的txt文件,支持网络路径或脚本目录。脚本内置过滤规则,自动剔除补丁包、Office组件及NVIDIA、Intel驱动等系统组件,兼容32位和64位系统。
先说核心目标:用VBS脚本收集域内远程或本地计算机上安装了哪些软件、Windows版本信息,然后以计算机名命名生成一个文本文件。结果可以保存到网络路径,也可以直接放在脚本所在目录。而且,这个脚本已经内置好了过滤规则——那些补丁包、Office组件、NVIDIA、Intel 驱动之类我们不关心的条目,会自动被剔除掉,省去人工筛选的麻烦。

目标
脚本的功能很明确:
- 收集域中远程计算机或本地计算机安装的软件及 Windows 版本;
- 结果保存为以计算机名命名的 .txt 文件(支持保存到网络路径或脚本所在目录);
- 兼容 32 位和 64 位系统;
- 自动过滤掉 Security Update、.NET Framework、Microsoft Visual C++、NVIDIA、Intel® 驱动等系统级组件,同时保留 Office 各版本的信息。
制作 VBS 脚本
把下面的代码复制出来,保存为一个 .vbs 文件(比如 InstalledSoftList.vbs),放到 D 盘根目录下就行。
On Error Resume Next
Const HKCU = &h80000001
Const HKLM = &H80000002
Const strKeyPath = "SoftwareMicrosoftWindowsCurrentVersionUninstall"
Const str64KeyPath = "SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall"
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
'FilePath = "\Server-FilePCSoftList"
FilePath = CreateObject("Scripting.FileSystemObject").GetFolder(".").Path & ""
Set Wshell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemobject")
'Set collected computers Name
set argus=wscript.arguments
if argus.count=0 then
strComputerName = Wshell.RegRead("HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParametersHostname")
else
strComputerName = argus(0)
end if
Set textWriteFile = objFSO.OpenTextFile(FilePath & ucase(strComputerName) &".txt",ForWriting,True,True)
Set objReg = GetObject("winmgmts://" & strComputerName & "/root/default:StdRegProv")
'Get OS Version
intRet = objReg.GetStringValue(HKLM, "SOFTWAREMicrosoftWindows NTCurrentVersion","ProductName",strOSVersion)
If intRet = 0 Then
intRet = objReg.GetStringValue(HKLM, "SOFTWAREMicrosoftWindows NTCurrentVersion","CSDVersion",strOSServicePack)
intRet = objReg.GetStringValue(HKLM, "SOFTWAREWow6432NodeMicrosoftWindows NTCurrentVersion","ProductName",str64BitOSVersion)
if intRet = 0 then
strOSVersion = strOSVersion & " 64bit"
end if
intRet = objReg.GetStringValue(HKLM, "SYSTEMCurrentControlSetControlNlsLanguage","InstallLanguage",OSLanguageCode)
if intRet = 0 then
select case OSLanguageCode
case "0804" '中文
strOSVersion = strOSVersion & " Chinese Version"
case "0411" '日文
strOSVersion = strOSVersion & " Japanese Version"
case "0409" '英文
strOSVersion = strOSVersion & " English Version"
case else '未知语言
strOSVersion = strOSVersion & " UnknownLanguage Version"
end select
end if
Else
strOSVersion = "OS Get Failed"
strOSServicePack = "NoFind"
End If
if InStr(LCase(strOSVersion),"windows")>0 then
textWriteFile.WriteLine("""" & ucase(strComputerName) & """" & vbTab & """" & strOSVersion & """" & vbTab & """" & strOSServicePack & """")
end if
'Display User Software.
objReg.EnumKey HKCU, strKeyPath,arrSubKeys
For Each strSubKey In arrSubKeys
intGet = objReg.GetDWORDValue(HKCU, strKeyPath & strSubKey,"SystemComponent",intSystemComponent)
If IsNull(intSystemComponent) then
intSystemComponent = 0
End If
intRet = objReg.GetStringValue(HKCU, strKeyPath & strSubKey,"ParentDisplayName",strName)
If intSystemComponent = 0 and intRet > 0 then
intRet = objReg.GetStringValue(HKCU, strKeyPath & strSubKey,"DisplayName",strName)
If strName <> "" And intRet = 0 And ignorePgm(strName) Then
strName = replace(replace(strName,vbCrLf,""),vbTab,"")
intRet = objReg.GetStringValue(HKCU, strKeyPath & strSubKey,"DisplayVersion",strVersion)
textWriteFile.WriteLine("""" & ucase(strComputerName) & """" & vbTab & """" & strName & """" & vbTab & """" & strVersion & """")
End If
End If
Next
'Display Machine 32bit Software.
objReg.EnumKey HKLM, strKeyPath,arrSubKeys
For Each strSubKey In arrSubKeys
intGet = objReg.GetDWORDValue(HKLM, strKeyPath & strSubKey,"SystemComponent",intSystemComponent)
If IsNull(intSystemComponent) then
intSystemComponent = 0
End If
intRet = objReg.GetStringValue(HKLM, strKeyPath & strSubKey,"ParentDisplayName",strName)
If intSystemComponent = 0 and intRet > 0 then
intRet = objReg.GetStringValue(HKLM, strKeyPath & strSubKey,"DisplayName",strName)
If strName <> "" And intRet = 0 And ignorePgm(strName) Then '
strName = replace(replace(strName,vbCrLf,""),vbTab,"")
intRet = objReg.GetStringValue(HKLM, strKeyPath & strSubKey,"DisplayVersion",strVersion)
textWriteFile.WriteLine("""" & ucase(strComputerName) & """" & vbTab & """" & strName & """" & vbTab & """" & strVersion & """")
End If
End If
Next
'Display Machine 64bit Software.
objReg.EnumKey HKLM, str64KeyPath,arrSubKeys
For Each strSubKey In arrSubKeys
intGet = objReg.GetDWORDValue(HKLM, str64KeyPath & strSubKey,"SystemComponent",intSystemComponent)
If IsNull(intSystemComponent) then
intSystemComponent = 0
End If
intRet = objReg.GetStringValue(HKLM, str64KeyPath & strSubKey,"ParentDisplayName",strName)
If intSystemComponent = 0 and intRet > 0 then
intRet = objReg.GetStringValue(HKLM, str64KeyPath & strSubKey,"DisplayName",strName)
If strName <> "" And intRet = 0 And ignorePgm(strName) Then
strName = replace(replace(strName,vbCrLf,""),vbTab,"")
intRet = objReg.GetStringValue(HKLM, str64KeyPath & strSubKey,"DisplayVersion",strVersion)
textWriteFile.WriteLine("""" & ucase(strComputerName) & """" & vbTab & """" & strName & """" & vbTab & """" & strVersion & """")
End If
End If
Next
textWriteFile.Close
function ignorePgm(strPgm)
If inStr(1,strPgm,"Microsoft Office ",1)<=0 then
'不输出Security Update、.NET Framework、Microsoft Visual C++、NVIDIA、Intel(R)的程序
ignorePgm = inStr(1,strPgm,"Security Update",1)<=0 _
And inStr(1,strPgm,".NET Framework",1)<=0 _
And inStr(1,strPgm,"Microsoft Visual C++",1)<=0 _
And inStr(1,strPgm,"NVIDIA",1)<=0 _
And inStr(1,strPgm,"Intel(R)",1)<=0
Else
'让个版本的Office能正常输出
ignorePgm = inStr(1,strPgm,"Microsoft Office ",1)>0 _
And (inStr(1,strPgm," 2000 ",1)>0 _
Or inStr(1,strPgm," 2003 ",1)>0 _
Or (inStr(1,strPgm,"Microsoft Office Access ",1)=1 And inStr(1,strPgm," MUI",1)<=0) _
Or strPgm="Microsoft Office Professional Plus 2007" _
Or strPgm="Microsoft Office Professional Plus 2010" _
Or strPgm="Microsoft Office Professional Plus 2016" _
Or strPgm="Microsoft Office Standard 2007" _
Or strPgm="Microsoft Office Standard 2010" _
Or strPgm="Microsoft Office Standard 2016" _
Or strPgm="Microsoft Office Standard 2019")
End If
end function
修改结果文件保存路径
脚本里有两行代码控制文件保存的位置(见下面高亮部分)。默认情况下,它会将 .txt 文件保存在当前 VBS 脚本所在的目录。如果你想把结果统一存到某个网络共享路径下,就取消第一行的注释,把路径改好,再把第二行注释掉即可。
'FilePath = "\Server-FilePCSoftList"
FilePath = CreateObject("Scripting.FileSystemObject").GetFolder(".").Path & ""
测试阶段直接使用默认路径就行,不需要改。
修改过滤条件(定制你不想看到的程序名)
脚本默认过滤掉 Security Update、.NET Framework、Microsoft Visual C++、NVIDIA、Intel® 驱动这几类条目。如果你需要增加或减少过滤项,直接修改 ignorePgm 函数里的判断逻辑即可。下面这段代码就是过滤核心:
'不输出Security Update、.NET Framework、Microsoft Visual C++、NVIDIA、Intel(R)的程序 ignorePgm = inStr(1,strPgm,"Security Update",1)<=0 _ And inStr(1,strPgm,".NET Framework",1)<=0 _ And inStr(1,strPgm,"Microsoft Visual C++",1)<=0 _ And inStr(1,strPgm,"NVIDIA",1)<=0 _ And inStr(1,strPgm,"Intel(R)",1)<=0
初次测试可以不修改,直接运行看看效果。
测试
测试方法1:收集本机软件
直接双击 InstalledSoftList.vbs 即可。假设本机计算机名是 PC-Name01,那么在脚本所在目录就会生成一个 PC-Name01.txt 文件。
测试方法2:收集远程计算机软件
打开 CMD 命令行,执行以下命令(假设远程计算机名为 PC-Name02):
cscript d:\InstalledSoftList.vbs PC-Name02
同样会在指定目录下生成 PC-Name02.txt 文件。
测试方法2的注意事项
如果生成的 .txt 文件是空的,通常是因为以下两个原因:
- 远程计算机与运行脚本的计算机必须在同一个域内,否则 WMI 连接会失败;
- 远程计算机的防火墙必须关闭,或者至少开启入站规则允许“Windows Management Instrumentation (WMI)”通过。
以上就是这个 VBS 脚本的全部内容。实测下来,无论是本地还是远程,都能稳定获取到干净的软件列表,特别适合运维场景下批量盘点资产。
Windows 10 是一款微软推出的经典操作系统,拥有硬件兼容性与多任务处理能力。它更偏向把系统状态查看和常用调节动作放在一起,适合需要持续观察和微调设备状态的场景。
极度公式是一款跨平台专业LaTeX公式识别编辑软件,支持OCR公式识别和多平台编辑。和使用说明,避免使用,享受完整功能与稳定支持。做扫描整理、文字提取和表格转换时,它能把识别后的处理步骤接得更顺,资料录入这类场景会省下不少时间。
















