How can I, using VBScripts -
1. backup everything under HKEY_LOCAL_MACHINE\SOFTWARE\Software1 before modifying it, so that in case of any problem we can easily restore by merging the saved subtree?
2. search and replace all F:\ with G:\?
Thanks!!!
Hi
Here you go:
sKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Software1"
sBackupFile = "c:\Backup\Software1.reg" ' folder(s) must exist!
Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1
Const OverwriteIfExist = -1
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
' do not overwrite an existing file
If Not oFSO.FileExists(sBackupFile) Then
' export the registry key to a file
sCmd = "regedit.exe /S /E:A """ & sBackupFile & """ " & """" & sKey & """"
oShell.Run sCmd, 0, True
Else
WScript.Echo "Backup file alredy exists, will use existing file" _
& " as source for replace function"
End If
' open and read the registry file
Set fFile = oFSO.OpenTextFile(sBackupFile, ForReading, _
FailIfNotExist, OpenAsASCII)
sContent = fFile.ReadAll
fFile.Close
' replace the drive pointer
sContent = Replace(sContent, "F:\", "G:\", 1, -1, vbTextCompare)
' create a temporary registry file
sTemp = oShell.ExpandEnvironmentStrings("%TEMP%\")
sTempFile = sTemp & oFSO.GetTempName
Set fFile = oFSO.CreateTextFile(sTempFile, OverwriteIfExist, OpenAsASCII)
fFile.WriteLine sContent
fFile.Close
' import the registry file
oShell.Run "regedit.exe /S """ & sTempFile & """", 1, True
' delete it
oFSO.DeleteFile sTempFile
WScript.Echo "Finished"
--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: http://www.microsoft.com/technet/scriptcenter