Export registry string

R

Rene

Hi expert!

I need some help. I need to write a VBA macro that will export a
defined branch of the registry into a *.reg file.

Can anybody point me in the right direction?

Thanks,
Rene
 
J

Jean-Guy Marcil

Rene was telling us:
Rene nous racontait que :
Hi expert!

I need some help. I need to write a VBA macro that will export a
defined branch of the registry into a *.reg file.

Can anybody point me in the right direction?

You can read the registry from Word VBA, like

aName = System.PrivateProfileString("", _
"HKEY_CURRENT_USER\Software\Microsoft\" _
& "Windows\CurrentVersion\Internet Settings", "EmailName")
MsgBox aName

If you really want to export a key:

Set objShell = CreateObject("WScript.Shell")
objShell.Exec "regedit.exe /a C:\MyExport.reg " _
& """HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"""

Can you write a dll add-in and use VB or VB.Net?
See this VB example
http://www.freevbcode.com/ShowCode.Asp?ID=259

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jay Freedman

Jean-Guy Marcil said:
Rene was telling us:
Rene nous racontait que :


You can read the registry from Word VBA, like

aName = System.PrivateProfileString("", _
"HKEY_CURRENT_USER\Software\Microsoft\" _
& "Windows\CurrentVersion\Internet Settings", "EmailName")
MsgBox aName

If you really want to export a key:

Set objShell = CreateObject("WScript.Shell")
objShell.Exec "regedit.exe /a C:\MyExport.reg " _
&
"""HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"""

Can you write a dll add-in and use VB or VB.Net?
See this VB example
http://www.freevbcode.com/ShowCode.Asp?ID=259

Very interesting... According to http://support.microsoft.com/kb/q168589/
the command-line switch for exporting from Regedit is /e rather than /a. I
tried both, on a Windows 2000 system, and both worked, in that they produced
files containing the same set of values. However, the one made with /a
starts with the line

REGEDIT4

while the one made with /e starts with the line

Windows Registry Editor Version 5.00

Version 5 of Regedit comes with Windows 2000 and later, while Version 4
shipped with Windows NT. I haven't tried importing the files to see whether
Regedit recognizes both equally well.
 
J

Jean-Guy Marcil

Jay Freedman was telling us:
Jay Freedman nous racontait que :
Very interesting... According to
http://support.microsoft.com/kb/q168589/ the command-line switch for
exporting from Regedit is /e rather than /a. I tried both, on a
Windows 2000 system, and both worked, in that they produced files
containing the same set of values. However, the one made with /a
starts with the line

So I guess to be on the safe side, the "e" switch should be used!
Honestly, I did not know about all this until I read the poster's
question... 5 minutes later (well, maybe 10!) I was writing my answer
(Thanks to Google and an appropriate use of search words!). I did test it,
and it seemed to work although, like you, I did not try re-importing the reg
file... There are limits to what I will do to help a poster... Screwing
around with my registry is well beyond those limits!

Thanks for the info.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top