Lou Pereira
asked on
How to find if a Reg key exists
I'm trying to create a script that will the registry (HKLM\Software\Microsoft\U pdates\Win dows Server 2003\SP3\ "keynamevar"). If the key exists then create a report text file. I've created the following, but when I test it does not report true findings! Thank you for your help
strComputer = "."
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const HKEY_LOCAL_MACHINE = &H80000002
dt = Replace(Date,"/","-")
strFileName = "C:\versions\" & dt & "-FreeSpace.txt"
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set objFile2 = objFSO.CreateTextFile(strF ileName, ForAppending, True)
Set objFile = objFSO.OpenTextFile("C:\ve rsions\pat ches.txt", 1)
' Registry values
Set oReg=GetObject("winmgmts:{ impersonat ionLevel=i mpersonate }!\\" & _
strComputer & "\root\default:StdRegProv" )
'objFile2.WriteLine "Date Modified: " & dt
Do Until objFile.AtEndOfStream
strCharacters = objFile.Readline
strKeyPath = "SOFTWARE\Microsoft\Update s\Windows Server 2003\SP3\"& strCharacters
strValueName = "InstalledDate"
oReg.GetExpandedStringValu e HKEY_LOCAL_MACHINE,strKeyP ath, _
strValueName,strValue
'If IsNull(strValueName) Then
if strValueName = "InstalledDate" Then
objFile2.WriteLine "Date Installed: " & strValue
oReg.GetExpandedStringValu e HKEY_LOCAL_MACHINE,strKeyP ath, _
strValueName1,strValue1
strValueName1 = "Description"
objFile2.WriteLine "Patch Installed: " & strValue1
Else
objFile2.WriteLine "Key (" & strCharacters & ") does not exist!!" & strValue1
End If
Loop
objFile.Close
objFile2.Close
strComputer = "."
Set objFSO = CreateObject("Scripting.Fi
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const HKEY_LOCAL_MACHINE = &H80000002
dt = Replace(Date,"/","-")
strFileName = "C:\versions\" & dt & "-FreeSpace.txt"
Set objFSO = CreateObject("Scripting.Fi
Set objFile2 = objFSO.CreateTextFile(strF
Set objFile = objFSO.OpenTextFile("C:\ve
' Registry values
Set oReg=GetObject("winmgmts:{
strComputer & "\root\default:StdRegProv"
'objFile2.WriteLine "Date Modified: " & dt
Do Until objFile.AtEndOfStream
strCharacters = objFile.Readline
strKeyPath = "SOFTWARE\Microsoft\Update
strValueName = "InstalledDate"
oReg.GetExpandedStringValu
strValueName,strValue
'If IsNull(strValueName) Then
if strValueName = "InstalledDate" Then
objFile2.WriteLine "Date Installed: " & strValue
oReg.GetExpandedStringValu
strValueName1,strValue1
strValueName1 = "Description"
objFile2.WriteLine "Patch Installed: " & strValue1
Else
objFile2.WriteLine "Key (" & strCharacters & ") does not exist!!" & strValue1
End If
Loop
objFile.Close
objFile2.Close
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.