Link to home
Start Free TrialLog in
Avatar of OPatiny
OPatiny

asked on

Exporting Registry key via VBS

Hi everybody,

I'm trying to use a VBS code found of this forum and adapt it for my need, but i'm totally lost.

I'm trying to export 3 registry entries to a file, but it's not working, because the registry entries contains space, and i really don't know how to solve this, and hope that someone could hear my pray :)

Here's my current code :

'===================
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

arrRegPaths = Array( _
      "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\ActiveX Compatibility\{F0E42D50-368C-11D0-AD81-00A0C90DC8D9}",_
      "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\ActiveX Compatibility\{F0E42D60-368C-11D0-AD81-00A0C90DC8D9}",_
      "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\ActiveX Compatibility\{F2175210-368C-11D0-AD81-00A0C90DC8D9}" _
      )

Const intForReading = 1
Const intUnicode = -1

strFileName = objShell.ExpandEnvironmentStrings("%UserProfile%") & "\Desktop\RegKeys.reg"

Set objRegFile = objFSO.CreateTextFile(strFileName, True, True)
objRegFile.WriteLine "Windows Registry Editor Version 5.00"

For Each strRegPath In arrRegPaths
      strCommand = "cmd /c REG EXPORT " & strRegPath & " " & Replace(strRegPath, "\", "_") & ".reg"
      objShell.Run strCommand, 0, True
      If objFSO.FileExists(Replace(strRegPath, "\", "_") & ".reg") = True Then
            'WScript.Sleep 10000 ' Wait one second to give the file time to close
            Set objInputFile = objFSO.OpenTextFile(Replace(strRegPath, "\", "_") & ".reg", 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, "\", "_") & ".reg", True
      End If
Next

objRegFile.Close
Set objRegFile = Nothing

MsgBox "Finished."
'===================

On array values, if i set it to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ it's working, but it seems to don't accept space.
Many thanks in advance for your help.



ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of OPatiny
OPatiny

ASKER

Great, ty very much, it worked like a charmed :)
No problem. Thanks for the grade.

Regards,

Rob.