我不想承认我浪费了大量时间来尝试调整返回已安装程序列表的 VB 脚本,并且我试图了解我哪里出错了。
我遇到的问题是,我在网上找到的每个“List Programs”类型脚本都会使用具有“DisplayName”字段的每个键填充一个文本文件。尽管进行了大量查找,但我找不到仅返回填充 add/remove 或 appwiz.cpl 的列表的列表。这是我发现的“Grab Everything”类型脚本的示例:
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject( "WScript.Shell" )
temp=oShell.ExpandEnvironmentStrings("%temp%")
Set objTextFile = objFSO.CreateTextFile(temp & "\software.txt", True)
strComputer = "."
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strKey2 = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
strEntry1a = "DisplayName"
strEntry1b = "QuietDisplayName"
Set objReg = GetObject("winmgmts://" & strComputer & _
"/root/default:StdRegProv")
objReg.EnumKey HKLM, strKey, arrSubkeys
For Each strSubkey In arrSubkeys
intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, _
strEntry1a, strValue1)
If intRet1 <> 0 Then
objReg.GetStringValue HKLM, strKey & strSubkey, _
strEntry1b, strValue1
End If
If strValue1 <> "" Then
objTextFile.WriteLine strValue1
End If
Next
objtextfile.close
Set objTextFile = objFSO.CreateTextFile(temp & "\software.txt", True)
objReg.EnumKey HKLM, strKey2, arrSubkeys
For Each strSubkey In arrSubkeys
intRet1 = objReg.GetStringValue(HKLM, strKey2 & strSubkey, _
strEntry1a, strValue1)
If intRet1 <> 0 Then
objReg.GetStringValue HKLM, strKey & strSubkey, _
strEntry1b, strValue1
End If
If strValue1 <> "" Then
objTextFile.WriteLine strValue1
End If
Next
objtextfile.close
因为找不到,所以决定自己做。查找 Windows 用来排除条目的字段非常容易。如果注册表中的 Uninstall 项中列出的所有项包含字段“ParentDisplayName”或“SystemComponent”,则它们将被排除。我所要做的就是引入一种方法来筛选包含上述字段的键,这样它们就不会添加到 ObjTextFile.WriteLine 中。
我的问题是应该为 null 的值会返回为“1”吗?我真的很想知道出了什么问题,所以我避免在未来浪费太多时间。
我终于开始工作的脚本在这里:
(请注意,提交给文本文件的“SystemComponent”和“ParentDisplayName”必须同时具有“1”才能被排除。但我不知道为什么它是“1”而不是 Null。
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject( "WScript.Shell" )
System=oShell.ExpandEnvironmentStrings("%systemroot%")
Set objTextFile = objFSO.CreateTextFile("installed.txt", True)
strComputer = "."
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strKey2 = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
strEntry1a = "DisplayName"
strEntry1b = "QuietDisplayName"
strEntry1c = "SystemComponent"
strEntry1d = "ParentDisplayName"
Set objReg = GetObject("winmgmts://" & strComputer & _
"/root/default:StdRegProv")
objReg.EnumKey HKLM, strKey, arrSubkeys
For Each strSubkey In arrSubkeys
Check1 = objReg.GetDWORDValue(HKLM, strKey & strSubkey, _
strEntry1c)
Check2 = objReg.GetStringValue(HKLM, strKey & strSubkey, _
strEntry1d)
intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, _
strEntry1a, strValue1)
If intRet1 <> 0 Then
objReg.GetStringValue HKLM, strKey & strSubkey, _
strEntry1b, strValue1
End If
If strValue1 <> "" and check1 = 1 and check2 = 1 Then
objTextFile.WriteLine strValue1
End If
Next
If objfso.folderexists (system & "\syswow64\") then
objReg.EnumKey HKLM, strKey2, arrSubkeys
For Each strSubkey In arrSubkeys
Check1 = objReg.GetDWORDValue(HKLM, strKey2 & strSubkey, _
strEntry1c)
Check2 = objReg.GetStringValue(HKLM, strKey2 & strSubkey, _
strEntry1d)
intRet1 = objReg.GetStringValue(HKLM, strKey2 & strSubkey, _
strEntry1a, strValue1)
If intRet1 <> 0 Then
objReg.GetStringValue HKLM, strKey & strSubkey, _
strEntry1b, strValue1
End If
If strValue1 <> "" and check1 = 1 and check2 = 1 then
objTextFile.WriteLine strValue1
End If
Next
objtextfile.close
else
end if
这就是我被抓住的地方;尝试无穷无尽的变化:
strEntry1c = "SystemComponent"
Check = objReg.GetDWORDValue(HKLM, strKey & strSubkey, _
strEntry1c)
IF isNull(Check) Then
intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, _
strEntry1a, strValue1)