OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 28-04-2011, 22:38
gorgo gorgo is offline
Senior Member
 
Join Date: Feb 2010
Posts: 169
Default

*UPDATE:

running this will give the error/stop Runtime Error 91, Object Variable or With block Variable not set.

Code:
Private Sub CommandButton1_Click()
Dim objShell As Object
Dim objFSO As Object
Dim arrRegPaths As Object
Dim strFileName As Object
Dim objRegFile As Object
Dim strRegPath As Object
Dim strCommand As Object
Dim objInputFile As Object
'Dim objShell As Object
Dim objInputFire As Object

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\PageNumberer_settings.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 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
Next

objRegFile.Close
Set objRegFile = Nothing

MsgBox "Finished."
End Sub
Reply With Quote
  #3  
Old 28-04-2011, 23:27
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,769
Blog Entries: 9
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Code

REM all the following lines:
Code:
'Dim arrRegPaths As Object
'Dim strFileName As Object
'Dim objRegFile As Object
'Dim strRegPath As Object
'Dim strCommand As Object
'Dim objInputFile As Object
'Dim objShell As Object
'Dim objInputFire As Object
and it should work, many of these variables should be be redefined to the proper types, but that is the quick answer that should work for you.

-Shelby
Reply With Quote
  #4  
Old 28-04-2011, 23:31
gorgo gorgo is offline
Senior Member
 
Join Date: Feb 2010
Posts: 169
Default

Quote:
Originally Posted by shelbym View Post
REM all the following lines:
Code:
'Dim arrRegPaths As Object
'Dim strFileName As Object
'Dim objRegFile As Object
'Dim strRegPath As Object
'Dim strCommand As Object
'Dim objInputFile As Object
'Dim objShell As Object
'Dim objInputFire As Object
and it should work, many of these variables should be be redefined to the proper types, but that is the quick answer that should work for you.

-Shelby
okay, did this. now error.
Attached Images
 
Reply With Quote
  #5  
Old 28-04-2011, 23:34
gorgo gorgo is offline
Senior Member
 
Join Date: Feb 2010
Posts: 169
Default

Quote:
Originally Posted by gorgo View Post
okay, did this. now error.
ah ha! got it to work now with alternate changes. verifying.
Attached Images
 
Reply With Quote
  #6  
Old 28-04-2011, 23:39
gorgo gorgo is offline
Senior Member
 
Join Date: Feb 2010
Posts: 169
Default

new problem. I got this far, now the *.reg file is empty (other than "Windows Registry Editor Version 5.00
"). What to do to tell this code to properly input the registry values as noted in the lines starting with HKEY_CURRENT_USER.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to find and remove duplicate entries in Listboxes? olympiatr CorelDRAW/Corel DESIGNER VBA 6 26-07-2010 20:29
Exporting Iluvtheravens General 1 14-03-2007 15:32
exporting to PSD zoom General 2 14-11-2006 12:23
Sorting entries in the object manager dan CorelDRAW/Corel DESIGNER VBA 1 18-08-2004 23:16
exporting to jpg ddonnahoe CorelDRAW/Corel DESIGNER VBA 7 26-01-2004 12:53


All times are GMT -5. The time now is 08:54.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com