使用 VBScript 获取作为 Windows 更新一部分的已安装更新列表 [英] Get list of installed updates as part of Windows Updates using VBScript

查看:43
本文介绍了使用 VBScript 获取作为 Windows 更新一部分的已安装更新列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 VBScript 非常陌生,我需要使用 VBScript 或任何其他工具获取已安装软件的列表(例如 Microsoft Visual C++ 2010 等)作为 Windows 更新的一部分.

I am very new to VBScript and I need to get the list of installed Softwares(For example Microsoft Visual C++ 2010 etc) as part of Windows Updates using VBScript or any.

如果安装的软件列在添加/删除程序使用 WMIC 下,我们可以获得列表.

If installed Softwares are listing under Add/Remove programs using WMIC we can get the list.

wmic product where \"Name like

但是,例如 Microsoft Visual C++ 2010 是作为 Windows 更新的一部分安装的,它没有在添加/删除程序下列出.

But, for example Microsoft Visual C++ 2010 is installed as a part of Windows Updates which is not listing under Add/Remove programs.

Microsoft Visual C++ 2010 列在注册表中.在这里,我需要使用 VBScript 或任何其他方式获取此类软件的列表.

Microsoft Visual C++ 2010 is listed in the Registries. Here I need to get the list of such Softwares using VBScript or any.

我需要这个用于 Windows 2008 R2 标准操作系统的脚本.

I need this script for Windows 2008 R2 Standard Operating System.

任何类型的方向或解决方案都会有很大帮助.

Any kind of directions or solutions will be of immense help.

提前致谢.

推荐答案

需要使用 wmi 注册表类来枚举注册表中的键.

You need to use wmi registry class to enumerate keys in the registry.

StdRegProv 类的 EnumKey 方法EnumKey 方法枚举路径的子项.有关通过 WMI 访问注册表的一般信息,请参阅获取注册表数据.

EnumKey Method of the StdRegProv Class The EnumKey method enumerates the subkeys for a path. See Obtaining Registry Data for general information on accessing the registry through WMI.

本主题使用托管对象格式 (MOF) 语法.有关使用此方法的信息,请参阅调用方法.

This topic uses Managed Object Format (MOF) syntax. For information about using this method, see Calling a Method.

uint32 EnumKey(
  uint32 hDefKey = 2147483650,
  string sSubKeyName,
  string sNames[]
);

参数定义密钥[in,可选] 包含 sSubKeyName 路径的注册表树,也称为配置单元.默认值为 HKEY_LOCAL_MACHINE.请注意,HKEY_DYN_DATA 是仅适用于 Windows 95 和 Windows 98 计算机的有效树.

Parameters hDefKey [in, optional] A registry tree, also known as a hive, that contains the sSubKeyName path. The default value is HKEY_LOCAL_MACHINE. Note that HKEY_DYN_DATA is a valid tree for Windows 95 and Windows 98 computers only.

Winreg.h 中定义了以下树.

The following trees are defined in Winreg.h.

Name Value 
HKEY_CLASSES_ROOT 2147483648
0x80000000 
HKEY_CURRENT_USER 2147483649
0x80000001 
HKEY_LOCAL_MACHINE 2147483650
0x80000002 
HKEY_USERS 2147483651
0x80000003 
HKEY_CURRENT_CONFIG 2147483653
0x80000005 
HKEY_DYN_DATA 2147483654
0x80000006 

sSubKeyName[in] 包含要枚举的子项的路径.名称[out] 子键字符串数组.返回值在 C++ 中,该方法返回一个 uint32 值,如果成功,该值为 0(零).如果函数失败,则返回值是 Winerror.h 中定义的非零错误代码.在 C++ 中,您可以使用带有 FORMAT_MESSAGE_FROM_SYSTEM 标志的 FormatMessage 函数来获取错误的一般描述.您还可以在 WMI 错误常量下查找返回值.在脚本或 Visual Basic 中,如果成功,该方法将返回一个整数值,该值为 0(零).如果函数失败,返回值是一个非零错误代码,您可以在 WbemErrorEnum 中查找.

sSubKeyName [in] A path that contains the subkeys to be enumerated. sNames [out] An array of subkey strings. Return Value In C++, the method returns a uint32 value that is 0 (zero) if successful. If the function fails, the return value is a nonzero error code that is defined in Winerror.h. In C++, you can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error. You can also look up return values under the WMI Error Constants. In scripting or Visual Basic, the method returns an integer value that is 0 (zero) if successful. If the function fails, the return value is a nonzero error code that you can look up in WbemErrorEnum.

示例代码

有关脚本代码示例,请参阅 WMI 任务:注册表和 TechNet ScriptCenter 脚本存储库.其他示例在更多信息中列出的书籍和文章中.

For script code examples, see WMI Tasks: Registry and the TechNet ScriptCenter Script Repository. Other examples are in books and articles listed in Further Information.

有关 C++ 代码示例,请参阅 WMI C++ 应用程序示例.

For C++ code examples, see WMI C++ Application Examples.

以下 VBScript 示例显示了如何使用 EnumKey 方法枚举在注册表项中列为子项的服务:

The following VBScript example shows how to use the EnumKey method to enumerate the services listed as subkeys in the registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services

您可以将脚本保存为扩展名为 .vbs 的文件,并通过在包含脚本的文件夹中执行命令行将输出发送到文件:cscript 文件名.vbs > output.txt

You can save the script as a file with a .vbs extension and send the output to a file by executing the command line in the folder that contains the script: cscript Filename.vbs > output.txt

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_ 
    strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Services"
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
WScript.Echo "Subkeys under " _
    & "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services"
For Each subkey In arrSubKeys
    WScript.Echo subkey
Next

<小时>

这解释了它的存储位置.


This explains where it is stored.

开始-所有程序-附件-右键单击命令提示符并选择以管理员身份运行.键入(或通过在命令提示符窗口中右键单击并选择粘贴来复制和粘贴).输入表格格式

Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type (or copy and paste by right clicking in the Command Prompt window and choosing Paste). Type for table format

wmic /output:"%userprofile%\desktop\WindowsInstaller.html" product get /format:htable

或表单格式

wmic /output:"%userprofile%\desktop\WindowsInstaller.html" product get /format:hform

它将在桌面上创建一个 html 文件.

It will create a html file on the desktop.

注意

这不是完整列表.这只是与 Windows Installer 一起安装的产品.没有任何功能.

This is not a full list. This is only products installed with Windows Installer. There is no feature for everything.

然而,正如我在上一篇文章中所说,几乎所有内容都列在注册表中.

However as I said in my previous post nearly everything is listed in the registry.

所以在命令提示符中看到它

So to see it in a command prompt

reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s

或在文件中

reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s>"%userprofile%\desktop\WindowsUninstall.txt"

在记事本中以不同的格式查看

To see it in notepad in a different format

单击开始 - 所有程序 - 附件 - 右键单击​​命令提示符并选择以管理员身份运行.输入 Regedit 并导航至

Click Start - All Programs - Accessories - Right click Command Prompt and choose Run As Administrator. Type Regedit and navigate to

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

右键单击卸载键并选择导出.如果您保存为reg文件(也有文本文件,它们是略有不同的文本格式)您需要右键单击该文件并选择编辑"以查看它.

Right click the Uninstall key and choose Export. If you save as a reg file (there is also text file, they are slightly different text formats) you need to right click the file and choose Edit to view it.

查看 Windows 更新

To view Windows Updates

wmic /output:"%userprofile%\desktop\WindowsUpdate.html" qfe  get /format:htable

这篇关于使用 VBScript 获取作为 Windows 更新一部分的已安装更新列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆