Login | |
|
 |
How can you edit a .REG file with vbscript? - 4/4/2006 8:12:22 AM
|
|
 |
|
| |
gwong
Posts: 4
Score: 0
Joined: 7/11/2005
Status: offline
|
I though this would be a simple process, like editing a text documnet, but apparently this is not the case. The fast and sloppy code: Option Explicit Dim oShell,sInput,f,fs Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 Set oShell = CreateObject("WScript.Shell") Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.OpenTextFile("C:\RegValue.reg",ForReading,True) sInput = f.ReadAll WScript.Echo sInput If InStr(sInput,"\TEMPHIVE\") Then sInput = Replace(sInput,"HKEY_LOCAL_MACHINE\TEMPHIVE","HKEY_CURRENT_USER") End If This is just a test; I am trying to determine why I cannnot read the .REG file properly. Whenever the script runs, it returns 3 characters of gibberish - that's it. Can someone point me in the right direction? The contents of the "C:\RegValue.reg" file: ______________________________________________________________________________ Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\TEMPHIVE\SOFTWARE\MICROSOFT\INTERNET EXPLORER\TYPEDURLS] "url1"="http://www.microsoft.com/isapi/redir.dll?prd=ie&pver=6&ar=msnhome" ______________________________________________________________________________
|
|
| |
|
|
|
 |
RE: How can you edit a .REG file with vbscript? - 4/4/2006 12:15:33 PM
|
|
 |
|
| |
Cybex
Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
|
What is it you are trying to do? Why not just read the registry and edit it directly? As far as your code... You are trying to open ir for reading but you never read it until at end of stream. You are going to have to read it line by line. You then try to write to something you opened for reading. These are just a few... If you just want to do it, it can be done fairly easy. Take another stab at it and post your updated code. Cybex
_____________________________
Common sense is not so common.
|
|
| |
|
|
|
 |
RE: How can you edit a .REG file with vbscript? - 4/4/2006 3:56:28 PM
|
|
 |
|
| |
gwong
Posts: 4
Score: 0
Joined: 7/11/2005
Status: offline
|
Below is the code reading the file line by line as you suggested. Same result. 3 characters of gibberish and nothing else. Option Explicit Dim oShell,sInput,f,fs Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 Set oShell = CreateObject("WScript.Shell") Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.OpenTextFile("C:\RegValue.reg",ForReading,True) Do While f.AtEndOfStream <> True sInput = f.ReadLine WScript.Echo "Original Input: " & sInput If InStr(sInput,"\TEMPHIVE\") Then sInput = Replace(sInput,"HKEY_LOCAL_MACHINE\TEMPHIVE","HKEY_CURRENT_USER") End If WScript.Echo "Corrected Input: " & sInput Loop This is a small part of a tool I am writing to backup user data. In the tool, I am mounting the user's registry hive to a temporary location so I may access their settings. In order to mount their profile, I am using REG.EXE /LOAD and mounting the file to HKLM\TEMPHIVE. The issue is, when I export the settings, the registry key reads just as you see it "HKLM\TEMPHIVE\<KEY>\<KEY>" and I would like to automatically replace the "HKLM\TEMPHIVE" to "HKEY_CURRENT_USER" so that when the .REG file is imported on the new machine, the settings return to the correct location. I have broken out this code from the main tool in order to troubleshoot why I am unable to read the text from a .REG file.
|
|
| |
|
|
|
 |
RE: How can you edit a .REG file with vbscript? - 4/5/2006 3:49:04 AM
|
|
 |
|
| |
ebgreen
Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
|
Do you then turn around and import the reg file? If that is the case, then I would recommend writing directly to the value in the registry and leave a file out of it altogether.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
|
|