我使用StdRegProv WMI类和GetExpandedStringValue以及GetStringValue方法在VBScript中遇到以下代码问题:
' Name the standard reg provider
sRegProv = "\\.\root\cimv2:StdRegProv"
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!" & _
sRegProv)
' OS is a 64-bit computer, and we need to check all paths
' Do the 32-bit stuff, as most things these days are 32-bit
sKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
' Fill arrKeys with every value under sKeyPath
oReg.EnumKey HKEY_LOCAL_MACHINE, sKeyPath, arrKeys
' step through each key until we find the one we want
For Each subKey in arrKeys
' Set the full key path to the next key
sFullKeyPath = sKeyPath & subKey
' Wscript.echo "Checking key: " & subKey
' Set the sDisplayName variable to the value in the key
oReg.GetStringValue HKEY_LOCAL_MACHINE, sFullKeyPath, "DisplayName", sDisplayName
Wscript.Echo "Found " & sDisplayName & " in key " & subKey
If sDisplayName = sAppName Then
Wscript.Echo "Found value: " & sDisplayName
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE, sFullKeyPath, "UninstallString", sUninstallString
GetRegUninstallString = sUninstallString
' Exit the function; we've found what we're looking for
Exit Function
End If
Next
我的问题是GetStringValue调用根本没有返回值,GetExpandedStringValue也没有。我没有检查名称和其他一些东西的逻辑尝试过这个。这是更大功能的一部分。
你在这段代码中看到的东西是我声明常量的地方,以及函数本身,它们在这里:
const HEKY_LOCAL_MACHINE = &H80000002
该函数有一个sAppName的输入参数,该参数是设置该值的位置。当我设置它时,我使用了正确的引用规则(例如,Microsoft Office ProfessionalPlus 2013是"例如Microsoft Office ProfessionalPlus 2013")。
请帮忙。我们遇到的问题是卸载程序在整个公司中不一致,我希望以编程方式解决问题,以便我们可以一劳永逸地解决问题,因为存在差异。我想使用Microsoft SCCM 2007部署此脚本,它可以很好地工作,如果我可以通过验证应用程序名称然后获取卸载值来解决问题。
我的大多数搜索结果都与在GetStringValue调用中没有提供out参数的人有关。我引用了以下MSDN文章: StdRegProv (WMI Class), GetStringValue
感谢您提前回复。我确定它有点傻。顺便说一句,操作系统是Windows 8.1 64位。
答案 0 :(得分:0)
我在这里的代码中添加了一行来确定查询sFullKeyPath的结果是什么,结果是2,这是不存在的密钥的错误。因此,更改以下内容解决了我的问题:
sFullKeyPath = sKeyPath & "\" & subKey
一旦改变了,脚本的其余部分就可以了。完全失败的唯一项目是没有“DisplayName”属性的注册表项。
我将此作为答案发布,以便人们可以阅读并查看结果。