ThinWorld Citrix Knowledgebase

Tuesday, 2 March 2010

Registry .REG backup Script

This Script reads in a .REG file and makes a backup of the registry area that the .REG will change when imported.

This is handy when you are given a .REG file and told to import it. The script will create backup .REG files for you to restore the machine to original values should the import cause issues.

Its not the prettiest of things and will create multiple backup REG files if there are multiple key paths. But you can highlight all the backup reg keys and import in the event of a restore.

'
' Backup Registry before importing a REG file
'
' This script is designed to be run before importing a .REG file
' It will export the current registry key values into a .REG file
' in order to make a restore to the original keys quick and simple.
'
' Input it a .REG file
' It will output to a folder of the same name a .REG file for each required Key
'

On error resume next

Set objFSO = CreateObject("Scripting.fileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Set objInputFile = objFSO.OpenTextFile(StrScript,1,False,0)

StrFolder = Wshshell.CurrentDirectory
StrScript = "tweak-bundle1.reg"
dim StrKey(1000)

StrPath = StrFolder & "\" & Left(StrScript,Len(StrScript)-4)

objFSO.CreateFolder (StrPath)

i=0
Do Until objInputFile.AtEndOfStream
i = i+1
strData = objInputFile.ReadLine
If Instr(Strdata,"[") > 0 Then
StrData = Left(StrData,Len(Strdata)-1)
StrData = Right(Strdata,Len(Strdata)-1)
StrKey(i) = Strdata
StrCommand = "REGEDIT /E " & CHR(34) & StrPath & "\" & i & ".reg" & CHR(34) & " " & CHR(34) & Strkey(i) & CHR(34)
Wshshell.Run Strcommand
End If
Loop

Labels:

0 Comments:

Post a Comment



<< Home