Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42215

Read a reg key, output to a text file

$
0
0
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")

arrRegPaths = Array( _
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\User Agent\Post Platform",_
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\User Agent\UA Tokens"_
)

Const intForReading = 1
Const intUnicode = -1

strFileName = "C:\GT_Log\CleanUpUA.txt"

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.

Viewing all articles
Browse latest Browse all 42215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>