Solved

registry

Posted on 2000-05-05
11
328 Views
Last Modified: 2010-05-02
Hi Experts

is there any way of extracting all the registry keys and value to a file
 What I want to do is try and make a small program to back up my registry incase my computer ever goes down.
can some please point my to the right place or maybe some one has some code

0
Comment
Question by:dreamvb
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2783211
Run "regedit".  Do an Registry -> Export Registry File.
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2783214
The resulting file will look something like:

REGEDIT4

[HKEY_LOCAL_MACHINE]
"FullLogging"="No"
"EnablePowerManagement"=hex:30,30,30,30
"IE State"=dword:00000000

[HKEY_LOCAL_MACHINE\Software]

[HKEY_LOCAL_MACHINE\Software\Microsoft]

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows]

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion]
"InstallType"=hex:03,00
"SetupFlags"=hex:08,05,00,00
"DevicePath"="C:\\WINDOWS\\INF"
"ProductType"="101"
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2783220
By the way, you can use RegEdit to import your previously saved file.

You can run RegEdit by clicking Start -> Run -> regedit
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Author Comment

by:dreamvb
ID: 2783230
I now that you can Export Registry File with reg edit but I want to Export Registry in Visual basic with code.
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2783253
GivenRandy changed the proposed answer to a comment
0
 
LVL 4

Expert Comment

by:gcs001
ID: 2783455
All you basically need to do is copy the files System.Dat and User.Dat to another location - these are your registry files.
Everytime Windows loads successfully it creates a copy of the System.Dat and User.Dat files to System.Da0 and User.Da0, so it creates a copy all on it's own.
Remember that these files are System/ Hidden/Read Only files, so you will have to set the attributes to Non System/Unhidden to copy the files to another location and then set the attributes back.

Here is a DOS batch file that you could use to do so ...

attrib -h -s user.dat
copy user.dat userdat.bkp
attrib +h +s user.dat

attrib -h -s system.dat
copy system.dat systemdat.bkp
attrib +h +s system.dat


To recover your registry you just have to the copy these backed up files to the Windows directory (or Winnt) in the correct file names, i.e. User.dat and System.Dat

Hope this helps.

Regards,
Grant.
0
 
LVL 3

Accepted Solution

by:
fibdev earned 20 total points
ID: 2783911
vb example of gcs001's example, you should make sure everything is setup correctly for this and the exe in this example should be in the system directory or the pathnames should be changed to look for the files in the system directory.  I would recomend backing up your registry using rededit befor you try this example.  If anyone sees any typos or anything I left out, please shout out asap:

Private Sub cmdRegBackup_Click()
Dim SourceFile, DestinationFile
SourceFile = "User.dat"  ' Define source file name.
SetAttr SourceFile, vbNormal
DestinationFile = "User.bkp"    ' Define target file name.
FileCopy SourceFile, DestinationFile    ' Copy source to target.
SetAttr SourceFile, vbHidden + vbReadOnly
SetAttr DestinationFile, vbHidden + vbReadOnly ' protect the backup files

SourceFile = "system.dat"
DestinationFile = "system.bkp"
FileCopy SourceFile, DestinationFile
SetAttr SourceFile, vbHidden + vbReadOnly
SetAttr DestinationFile, vbHidden + vbReadOnly ' protect the backup files

Label1.Caption = "Registry backup successful"
End Sub

Private Sub cmdRestoreReg_Click()
Dim SourceFile, DestinationFile
SetAttr SourceFile, vbNormal
SourceFile = "User.bkp"  ' Define source file name.
DestinationFile = "User.dat"    ' Define target file name.
FileCopy SourceFile, DestinationFile    ' Copy source to target.
SetAttr SourceFile, vbHidden + vbReadOnly
SetAttr DestinationFile, vbHidden + vbReadOnly


SourceFile = "system.bkp"
DestinationFile = "system.dat"
FileCopy SourceFile, DestinationFile
SetAttr SourceFile, vbHidden + vbReadOnly
SetAttr DestinationFile, vbHidden + vbReadOnly

Label1.Caption = "Registry restore successful"
End Sub

' this example requires two command buttons and a label
0
 
LVL 4

Expert Comment

by:gcs001
ID: 2783942
I wouldn't advise running the Registry restore from within Windows, i.e. rather boot into DOS (not a DOS window!!!) and do the restore from there, either with a DOS batch file or manually copy the files.
0
 
LVL 3

Expert Comment

by:fibdev
ID: 2783944
Hey gcs,

What if you did the file coping as demonstrated in my vbexample, then forced the system to reboot?  I agree, you're probably right and it should be advised to do all this in native dos, but the question was asking for a vb solution.

:)

On second thought, Use gcs's example and create backup and restore batch files to be run under dos.
0
 
LVL 3

Expert Comment

by:fibdev
ID: 2784549
Uh ...

Thanks for the points.  I know I offered a solution, but to be honest ...  gcs001 is right about making changes like this in native dos.  *shrug*
0
 
LVL 4

Expert Comment

by:gcs001
ID: 2787143
No problem.
All we're here to do is help ... the points are just a bonus!
Glad you came right dreamvb.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question