Looking to read a registry key, output it to a text file. I will then do some work to cleanup the reg key, read it again, and write the second set of results same txt file so we have a before and after results.
I have some logic but I don't think its "graceful" enough and currently do not know how to append the after results to the same text file:
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ObjReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
Set objRegFile = objFSO.CreateTextFile(strFileName, True, True)
objRegFile.WriteLine "IE User Agent Strings:"
For Each strRegPath In arrRegPaths
strCommand = "cmd /c REG EXPORT """ & strRegPath & """ """ & Replace(strRegPath, "\", "_") & ".txt"""
objShell.Run strCommand, 0, True
If objFSO.FileExists(Replace(strRegPath, "\", "_") & ".txt") = True Then
'WScript.Sleep 10000 ' Wait one second to give the file time to close
Set objInputFile = objFSO.OpenTextFile(Replace(strRegPath, "\", "_") & ".txt", intForReading, False, intUnicode)
If Not objInputFile.AtEndOfStream Then
objInputFile.SkipLine
objRegFile.Write objInputFile.ReadAll
End If
objInputFile.Close
Set objInputFile = Nothing
objFSO.DeleteFile Replace(strRegPath, "\", "_") & ".txt", True
End If
Next
Delete some values....
Read the key again....
write the second set of results to the text file created earlier.
Worked this out but, as with VBscript, Im sure there could be any number of ways: Here's what I came up with. The logic is to output the strings in this key to a text file, clean them up by targeting specific strings for deletion, and then append the txt file with the current key.
on error resume next
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objRegFile = objFSO.CreateTextFile(strFileName)
objregfile.close
Set objRegFile = objFSO.opentextfile(strFileName,8)
objRegFile.WriteLine "IE User Agent Strings Before Clean Up:"
For Each strRegPath In arrRegPaths
strCommand = "cmd /c REG EXPORT """ & strRegPath & """ """ & Replace(strRegPath, "\", "_") & ".txt"""
objShell.Run strCommand, 0, True
If objFSO.FileExists(Replace(strRegPath, "\", "_") & ".txt") = True Then
'WScript.Sleep 1000 ' Wait one second to give the temp file time to close
Set objInputFile = objFSO.OpenTextFile(Replace(strRegPath, "\", "_") & ".txt", intForReading, False, intUnicode)
If Not objInputFile.AtEndOfStream Then
objInputFile.SkipLine
objRegFile.Write objInputFile.ReadAll
End If
objInputFile.Close
Set objInputFile = Nothing
objFSO.DeleteFile Replace(strRegPath, "\", "_") & ".txt", True
End If
Next
objregfile.close
'****************************************************************
Set objRegFile = objFSO.OpenTextFile(strFileName,8)
objRegFile.WriteLine "IE User Agent Strings After Clean Up:"
For Each strRegPath In arrRegPaths
strCommand = "cmd /c REG EXPORT """ & strRegPath & """ """ & Replace(strRegPath, "\", "_") & ".txt"""
objShell.Run strCommand, 0, True
If objFSO.FileExists(Replace(strRegPath, "\", "_") & ".txt") = True Then
'WScript.Sleep 10000 ' Wait one second to give the file time to close
Set objInputFile = objFSO.OpenTextFile(Replace(strRegPath, "\", "_") & ".txt", intForReading, False, intUnicode)
If Not objInputFile.AtEndOfStream Then
objInputFile.SkipLine
objRegFile.Write objInputFile.ReadAll
End If
objInputFile.Close
Set objInputFile = Nothing
objFSO.DeleteFile Replace(strRegPath, "\", "_") & ".txt", True
End If
Next