我討厭承認我浪費了大量時間試圖調整一個VB腳本,該腳本返回已安裝程序的列表,並試圖瞭解我出錯的位置。爲什麼不存在的註冊表值回到「1」而不是空值?
我遇到的問題是,我在網上找到的每個「列表程序」類型腳本都會填充每個具有「DisplayName」字段的鍵的文本文件。儘管看了很多,我找不到一個只返回填充add/remove或appwiz.cpl的列表。這是「搶一切」類型的腳本,我發現的一個例子:
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用來排除條目的字段非常簡單。如果包含字段「ParentDisplayName」或「SystemComponent」,則註冊表中的「卸載」鍵中列出的所有鍵均被排除。我所要做的就是引入一種方法來屏蔽包含上述字段的鍵,以便它們不會被添加到ObjTextFile.WriteLine中。
我的問題是應該爲null的值是否會返回爲「1」?我真的很想知道出了什麼問題,所以我避免在將來浪費太多時間。
腳本我終於得到工作是在這裏:
(注意提交的文本文件必須以同時具有「SystemComponent」和「1」,「ParentDisplayName」不排除,但我有。不知道爲什麼它是「1」,而不是空
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)
strValue1沒有得到在循環也許它的價值重新初始化? – UnhandledExcepSean 2013-02-10 04:31:00
@SpectralGhost否,調用'GetStringValue'時總會重新初始化'strValue1'。 – 2013-02-10 12:32:51