View Single Post
  #1  
Old 28-04-2011, 22:14
gorgo gorgo is offline
Senior Member
 
Join Date: Feb 2010
Posts: 169
Default exporting registry entries to a *.reg file

I found this code:

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

arrRegPaths = Array( _
      "HKEY_CURRENT_USER\Software\VB and VBA Program Settings\PNPreset1\", _
      "HKEY_CURRENT_USER\Software\VB and VBA Program Settings\PNPreset2\", _
      "HKEY_CURRENT_USER\Software\VB and VBA Program Settings\PNPreset3\", _
      "HKEY_CURRENT_USER\Software\VB and VBA Program Settings\PNPreset4\" _
      )

Const intForReading = 1
Const intUnicode = -1

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

For Each strRegPath In arrRegPaths
      strCommand = "cmd /c REG EXPORT " & strRegPath & " " & Replace(strRegPath, "\", "_") & ".reg"
      objShell.Run strCommand, 0, True
      Set objRegFile = objFSO.CreateTextFile(strFileName, True, True)
      objRegFile.WriteLine "Windows Registry Editor Version 5.00"
      If objFSO.FileExists(Replace(strRegPath, "\", "_") & ".reg") = True Then
            'WScript.Sleep 1000 ' 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
      objRegFile.Close
      Set objRegFile = Nothing
Next

MsgBox "Finished."
But if I use this in a button in a form and run it, I get a Compile Error, Variable not defined at line ObjShell. How do I define it?
Reply With Quote