Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

registry

Posted on 2000-05-05
11
Medium Priority
?
352 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 80 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

877 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