WMI MOF文件与两个注册表密钥



查询Win32_Products可能需要很长时间,当试图查询很多计算机时,这让我感到沮丧。我以前从未使用过MOF文件,但有人建议"创建"一个新的名称空间,其中包含我正在从注册表中查找的信息。

我被指向以下MOF代码:

    #PRAGMA AUTORECOVER
    qualifier dynamic:ToInstance;
    qualifier ProviderClsid:ToInstance;
    qualifier ClassContext:ToInstance;
    qualifier propertycontext:ToInstance; 
    [dynamic, provider("RegProv"),
        ProviderClsid("{fe9af5c0-d3b6-11ce-a5b6-00aa00680c3f}"),
        ClassContext
        ("local|HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall")
    ] 
    class Software {
        [key] string KeyName;
        [read, propertycontext("Publisher")] string Vendor;
        [read, propertycontext("DisplayName")] string ProductName;
        [read, propertycontext("DisplayVersion")] string Version;
        [read, propertycontext("InstallDate")] string InstallDate;
        [read, propertycontext("InstallLocation")] string InstallLocation;
        [read, propertycontext("InstallSource")] string InstallSource;
        [read, propertycontext("UninstallString")] string UninstallString;
    };

这工作很棒,但是我怎么能让这个检查软件和软件Wow6432Node路径?我试过在VM上玩它,但没有运气,只是在黑暗中刺。

我试着:

    ("local|HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall")
    ("local|HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall")

    ("local|HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall",
    "local|HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall")

和其他一些随机的想法。似乎什么都不管用。如何从两个注册表路径收集信息?

我将感激任何帮助!

创建两个单独的MOF文件(每个注册表路径一个),或者使用多个实例化的__Win32Provider,如下所示

#PRAGMA AUTORECOVER
#pragma namespace("\\.\root\CimV2")
qualifier dynamic:ToInstance;
qualifier ProviderClsid:ToInstance;
qualifier ClassContext:ToInstance;
qualifier propertycontext:ToInstance; 
Instance of __Win32Provider as $prov32bit
{
  Name = "RegProv32";
  // ClsId = "{fe9af5c0-d3b6-11ce-a5b6-00aa00680c3f}";
};
Instance of __Win32Provider as $prov64bit
{
  Name = "RegProv64";
  // ClsId = "{fe9af5c0-d3b6-11ce-a5b6-00aa00680c3f}";
};
[dynamic, provider($prov32bit),
    ProviderClsid("{fe9af5c0-d3b6-11ce-a5b6-00aa00680c3f}"),
    ClassContext
    ("local|HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")
] 
[dynamic, provider($prov64bit),
    ProviderClsid("{fe9af5c0-d3b6-11ce-a5b6-00aa00680c3f}"),
    ClassContext
    ("local|HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall")
] 

非常确定class Software部分也有必要加倍。不确定所有ToInstance限定符口味的正确性。最后,上面的脚本不关心Wow6432Node的存在。不过,这个解决方案看起来不错:

这个脚本创建一个WMIWin32_AddRemovePrograms(和,在64位系统,Win32_AddRemovePrograms32用于32位应用程序)通过注册表提供程序。然后可以查询它们以列出已安装的列表应用程序(和版本)和执行比运行相同的快得多使用PowerShell注册表提供程序查询。此外,他们可以可用于GPO策略等

最新更新