Avatar of Jeff Davies
Jeff DaviesFlag for United States of America

asked on 

Need help with a text parsing script

ADMINS PLEAE NOTE THAT THIS IS FOR INTERNAL USE ONLY!!!! The company I work for has multiple sites and the different departments have different requests for the following information...

Ok, here's the deal, I have recently created a universal restore DVD using Acronis TIE. The image file is of a SYSPREP'ed Windows XP install. The original computer was registered with the Owner and Company name being the following: "Clone User" with "Clone Company". During the recovery process the Windows mini-wizard comes up and asks for the "new" Owner name and Organization. This data is confirmed to be stored in "HKLM\Software\Microsoft\Windows NT\CurrentVersion" under the values "RegisteredOwner" and "RegisteredOrganization" (See Code Snippet below shows an example REG EXPORT of that key).

Now for the fun part, I need to create a script that can be run to parse the values of RegisteredOwner and use the name contained there to replace all instances of data values = "Clone User" in the registry. Then do the same for RegisteredOrganization. So far I have created a .bat file that runs the command {REG EXPORT "HKLM\Software\Microsoft\Windows NT\CurrentVersion" new.reg} to generate a .reg file (plain text) with the contents looking like the code snippet. Then (manually) I created a .reg file called "clone.reg" containing all the keys showing Clone User and Clone Company. My origonal thought was to run the .bat file which creates the "new.reg" file containing the new info, the .bat file then executes a script file(part I need help with) that parses out the 2 values and basicly does a "Replace All" type function of the values in the "clone.reg" and save the file, then the .bat file would invoke a "REG IMPORT clone.reg" to merge the new data into the registry.

I have searched high and low on the net and nothing really goes into much detail about this kind of project. I might be over thinking the whole process here (is it possible to just run directly against the registry  itself with out having to import & export?), so if there is another way to script this then great. My only requirement is: it has to be automatic requiring no end-user input and must be executable from a command line.

Windows Registry Editor Version 5.00
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
bla
bla
bla
"RegisteredOrganization"="New Company Name Here"
"RegisteredOwner"="New Owner Name Here"
bla
bla
bla

Open in new window

VB ScriptWindows Batch

Avatar of undefined
Last Comment
RobSampson
Avatar of purplepomegranite
purplepomegranite
Flag of United Kingdom of Great Britain and Northern Ireland image

There are various code snippets around that show how to recursively search the registry, which is basically what you want to do.

http://www.eggheadcafe.com/forumarchives/scriptingVisualBasicscript/Aug2005/post23621926.asp

http://nerds-central.blogspot.com/2008/03/recursive-registry-hive-listing-for.html

Once you've located a value, it is very simple to change it.
Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, from what you've said, I'm going to assume that you already have a registry file that contains the paths to the values that you need to change.

That registry file contains the strings "Clone User" and "Clone Company", and is now your template.

So, if you run the code below (a VBS file), it will read the contents of the reg file, replace all "Clone User" occurences with a user that you enter in an Input Box, and also replace "Clone Company" occurences with a company that you enter in an Input Box. Then it will import that information when you remove the apostrophe from this line:

'objShell.Run strCommand, 1, True

Regards,

Rob.
strTemplateRegFile = "C:\TemplateRegFile.reg"
strNewRegFile = "C:\NewRegFile.reg"
strNewUser = InputBox("Please enter a new user name:", "User name", "New User")
strNewCompany = InputBox("Please enter a new company name:", "Computer name", "New Company")
 
If Trim(strNewUser) <> "" And Trim(strNewCompany) <> "" Then
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objShell = CreateObject("WScript.Shell")
	Const intForReading = 1
	Const intUniCode = -1
	Set objTemplateRegFile = objFSO.OpenTextFile(strTemplateRegFile, intForReading, False, intUniCode)
	strContents = objTemplateRegFile.ReadAll
	objTemplateRegFile.Close
	Set objTemplateRegFile = Nothing
	strContents = Replace(strContents, "Clone User", strNewUser)
	strContents = Replace(strContents, "Clone Company", strNewCompany)
	Set objNewRegFile = objFSO.CreateTextFile(strNewRegFile, True, intUniCode)
	objNewRegFile.Write strContents
	objNewRegFile.Close
	Set objNewRegFile = Nothing
	strCommand = "regedit /s """ & strNewRegFile & """"
	'objShell.Run strCommand, 1, True
	MsgBox "New registry settings imported."
Else
	If Trim(strNewUser) = "" Then MsgBox "New user was empty. Registry settings not changed."
	If Trim(strNewCompany) = "" Then MsgBox "New company was empty. Registry settings not changed."
End If

Open in new window

Avatar of RobSampson
RobSampson
Flag of Australia image

BTW, I tested with TemplateRegFile.reg having this in it.

Rob.
Windows Registry Editor Version 5.00
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"RegisteredOrganization"="Clone Company"
"RegisteredOwner"="Clone User"

Open in new window

Avatar of Jeff Davies
Jeff Davies
Flag of United States of America image

ASKER

Rob,

The idea behind your script would work, however for it to work on my case the input boxes need to be replaced with code to obtain values from either the registry itself, or from the new.reg file my .bat file generates. So you know, clone.reg contains an export of all keys containing the old owner and company names, the new.reg file contains the new values (see code in original post). Then once the alterations are done to the clone.reg file the script needs to save it's changes and quit. I can take care of the import process via my .bat file at that point.
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Jeff Davies
Jeff Davies
Flag of United States of America image

ASKER

Looks like that might do it, will check in the morning and let you know.
Avatar of RobSampson
RobSampson
Flag of Australia image

No problem. I can wait :-P

Rob.
Avatar of Jeff Davies
Jeff Davies
Flag of United States of America image

ASKER

Rob (Just updated the points on this one, as I am running into time constraints),

Finally got a chance to try the new script, but it isn't working the way I need it to. It appears to be extracting the string {"RegisteredOrginization="John Smith"} and looking for {"RegisteredOrginization="Clone User"} to update the string in full. What I need is for it to pull JUST the {John Smith} from the first file(new.reg) and replace instances of "Clone User" with "John Smith". Keep in mind that the name contained in new.reg will differ, and this script needs to read anything after {"RegisteredOrginization="} and end after the last ". This is where I am lost when it comes to scripting, heince the title of this project referencing "parsing". I have attached a clip of each of the .reg files for you to see what I am dealing with.
new.reg file contents (This file is actually about 1000 lines of info, but the date you need is listed here, and is the only instance starting with "Registered...") 
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"RegisteredOrganization"="John Smith"
"RegisteredOwner"="IT Department"
=============================================================
 
clone.reg file contents...
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\.NETFramework\1.1\S867460]
"InstalledBy"="Clone User"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\MSXML4SP2\Q936181]
"InstalledBy"="Clone User"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Registration]
"NAME"="Clone User"
"COMPAN"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\CyberLink\PowerDVD8]
"UserName"="Clone User"
"Company"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\0B79C053C7D38EE4AB9A00CB3B5D2472\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\0E23E40C6140D434FA9B96967D309AFE\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\4F57260AB42358E4596E782BDC274910\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\6030E61781384634B8F8C04C9E73B6CA\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\68AB67CA330100007706010000000020\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\68AB67CA7DA73301B7448A0100000030\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\8A0F842331866D117AB7000B0D610007\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\9040110900063D11C8EF10054038389C\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\9040150900063D11C8EF10054038389C\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\90401A0900063D11C8EF10054038389C\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\9040B30900063D11C8EF10054038389C\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\InstallShield_{2BF2E31F-B8BB-40A7-B650-98D28E0F7D47}]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\InstallShield_{6BE2A4A4-99FB-48ED-AE1E-4E850389F804}]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\PowerQuest\PartitionMagic\8.0\UserInfo]
"Name"="Clone User"
"Company"="Clone Company"

Open in new window

changeUC.zip
The attached is Rob's code updated so that it does what you need.
strCloneRegFile = "d:\ee\Reg\Clone.reg"
strNewRegFile = "d:\ee\Reg\new.reg"
 
'Array configuration Is
'<Field Name>;<Default Value in Clone File>
arrFields = Array(_
	"RegisteredOrganization;Clone Company", _
	"RegisteredOwner;Clone User" _
	)
 
Set regExpression = New RegExp
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Const intForReading = 1
 
Set objCloneRegFile = objFSO.OpenTextFile(strCloneRegFile, intForReading, False)
strCloneContents = objCloneRegFile.ReadAll
objCloneRegFile.Close
Set objCloneeRegFile = Nothing
 
Set objNewRegFile = objFSO.OpenTextFile(strNewRegFile, intForReading, False)
strNewContents = objNewRegFile.ReadAll
objNewRegFile.Close
Set objNewRegFile = Nothing
 
For Each strFieldAndDefault In arrFields
	strField = Split(strFieldAndDefault, ";")(0)
	strDefault = Split(strFieldAndDefault, ";")(1)
	
	'i=InStr(1,strCloneContents,"""" & strField & """=""" & strDefault & """"
	'if i>0 then
	
	With regExpression
	    .Global = True
	    .IgnoreCase = true
	    'Match a space (\s)
	    .Pattern = """" & strField & """="".*"""
	End With
	
    Set colMatches = regExpression.Execute(strNewContents)
    If colMatches.Count > 0 Then
    	For Each objMatch In colMatches
    		strValue = objMatch.Value
			strReplaceValue=Split(strValue,"""=""")(1)
			wscript.echo strReplaceValue
			if Len(strReplaceValue)>0 then
				strReplaceValue=Left(strReplaceValue, len(strReplaceValue)-1)
				wscript.echo strReplaceValue
				strCloneContents=Replace(strCloneContents,strDefault,strReplaceValue)
			end if
    	Next
    Else
    	strValue = ""
    End If
Next
 
'strContents = Replace(strContents, "Clone User", strNewUser)
strContents = Replace(strContents, "Clone Company", strNewCompany)
Set objCloneRegFile = objFSO.CreateTextFile(strCloneRegFile & ".txt", True, intUniCode)
objCloneRegFile.Write strCloneContents
objCloneRegFile.Close
Set objCloneRegFile = Nothing
strCommand = "regedit /s """ & strCloneRegFile & """"
'objShell.Run strCommand, 1, True
MsgBox "New registry settings imported."

Open in new window

Nope... sorry, left some code in and took some out that I needed for my testing...
Below is correct, though you may need to change:
const intUniCode = 0
back to
const intUniCode=-1
And the file paths to the reg files.

strCloneRegFile = "d:\ee\Reg\Clone.reg"
strNewRegFile = "d:\ee\Reg\new.reg"
 
'Array configuration Is
'<Field Name>;<Default Value in Clone File>
arrFields = Array(_
	"RegisteredOrganization;Clone Company", _
	"RegisteredOwner;Clone User" _
	)
 
Set regExpression = New RegExp
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Const intForReading = 1
Const intUniCode = 0
 
Set objCloneRegFile = objFSO.OpenTextFile(strCloneRegFile, intForReading, False, intUniCode)
strCloneContents = objCloneRegFile.ReadAll
objCloneRegFile.Close
Set objCloneeRegFile = Nothing
 
Set objNewRegFile = objFSO.OpenTextFile(strNewRegFile, intForReading, False, intUniCode)
strNewContents = objNewRegFile.ReadAll
objNewRegFile.Close
Set objNewRegFile = Nothing
 
For Each strFieldAndDefault In arrFields
	strField = Split(strFieldAndDefault, ";")(0)
	strDefault = Split(strFieldAndDefault, ";")(1)
	
	
	With regExpression
	    .Global = True
	    .IgnoreCase = true
	    'Match a space (\s)
	    .Pattern = """" & strField & """="".*"""
	End With
	
    Set colMatches = regExpression.Execute(strNewContents)
    If colMatches.Count > 0 Then
    	For Each objMatch In colMatches
    		strValue = objMatch.Value
			strReplaceValue=Split(strValue,"""=""")(1)
			if Len(strReplaceValue)>0 then
				strReplaceValue=Left(strReplaceValue, len(strReplaceValue)-1)
				strCloneContents=Replace(strCloneContents,strDefault,strReplaceValue)
			end if
    	Next
    Else
    	strValue = ""
    End If
Next
 
'strContents = Replace(strContents, "Clone User", strNewUser)
strContents = Replace(strContents, "Clone Company", strNewCompany)
Set objCloneRegFile = objFSO.CreateTextFile(strCloneRegFile & ".txt", True, intUniCode)
objCloneRegFile.Write strCloneContents
objCloneRegFile.Close
Set objCloneRegFile = Nothing
strCommand = "regedit /s """ & strCloneRegFile & """"
'objShell.Run strCommand, 1, True
MsgBox "New registry settings imported."

Open in new window

Avatar of Jeff Davies
Jeff Davies
Flag of United States of America image

ASKER

purplepomegranite,

I tried it and it just as you posted with const intUniCode = 0, and it gave me an error on line 58 (it also created a blank clone.reg.txt file), then tried with const intUniCode = 1 and it gave me an error on line 18. Plus from the looks of it (i might be wrong here), it appears that the code you posted only grabs the new name to replace "Clone User" and not the new company name to replace "Clone Company".
It replaces both values as you asked... I tested on reg files you have posted above, and an example one containing the actual user. I said you needed to replace:

const intUniCode = 0

with

 const intUniCode = -1

Note the minus sign - very important! I tested without simply because my test files weren't unicode.  As it was originally -1, I presume yours were.
Avatar of Jeff Davies
Jeff Davies
Flag of United States of America image

ASKER

purplepomegranite,

Sorry, just caught that, now no script errors, but NOTHING happens. No alterations are done to the clone.reg file and I am completely lost in the code (it makes me run circles im my head). I am a network admin, my area of expertise is networking routing and system maintenance. I took several classes over 6 years ago and really don't remember much. Thankyou in advance for any help you or anyone else can provide.
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Jeff Davies
Jeff Davies
Flag of United States of America image

ASKER

Rob & purplepomegranite, Thankyou for all your help, I finally got it working just as I needed. I couldn't have pulled this off without your help I really appreciate this.
Avatar of Jeff Davies
Jeff Davies
Flag of United States of America image

ASKER

Finally got everything working, thanks guys.
If anyone cares, I have inserted a copy of the code for the base bat,vbs & reg files. Hope this helps someone else down the road. The only thing I wish this script did was eliminate the need for the batch files and exporting/importing of .reg files (make it cleaner), but I can allways add a second command line in my sysprep.ini file to delete the C:|DRIVERS\UCUPDATE directory after I am done. That will clean up everything and leave no trace of my alterations. The end result will be, the end user starts the sysprep'd machine, and whatever is inserted into the mini-wizard, willl filter thru the other software allready preinstalled (Office, Acrobat, MS updates...ect) and the installed by information will not show the origonal user and company. Like I said before, the company I work for has several sub-companies and most of them don't want their registration info to reflect either the parent company or other related companies. This really helps me out in system deployments.

================changeuc.bat=========================
@Echo Off
Echo Extracting New Owner and Orginization info from Registry
Echo Please Wait....
REG EXPORT "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" C:\DRIVERS\UCUPDATE\new.reg
Echo Extracting Complete!
Echo Processing Extracted data...
C:\DRIVERS\UCUPDATE\clonereplace.vbs
Echo Processing Complete!
Echo Merging new Data into Registry...
REG IMPORT C:\DRIVERS\UCUPDATE\processed.reg
Echo Data merge complete!
Echo System is now fully customized for the new owner!!!
 
================clonereplace.vbs=====================
strCloneRegFile = "C:\DRIVERS\UCUPDATE\clone.reg"
strNewRegFile = "C:\DRIVERS\UCUPDATE\new.reg"
 
'Array configuration Is
'<Field Name>;<Default Value in Clone File>
arrFields = Array(_
	"RegisteredOrganization;Clone Company", _
	"RegisteredOwner;Clone User" _
	)
 
Set regExpression = New RegExp
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Const intForReading = 1
Const intUniCode = -1
 
Set objCloneRegFile = objFSO.OpenTextFile(strCloneRegFile, intForReading, False, intUniCode)
strCloneContents = objCloneRegFile.ReadAll
objCloneRegFile.Close
Set objCloneeRegFile = Nothing
 
Set objNewRegFile = objFSO.OpenTextFile(strNewRegFile, intForReading, False, intUniCode)
strNewContents = objNewRegFile.ReadAll
objNewRegFile.Close
Set objNewRegFile = Nothing
 
For Each strFieldAndDefault In arrFields
	strField = Split(strFieldAndDefault, ";")(0)
	strDefault = Split(strFieldAndDefault, ";")(1)
	
	
	With regExpression
	    .Global = True
	    .IgnoreCase = true
	    'Match a space (\s)
	    .Pattern = """" & strField & """="".*"""
	End With
	
    Set colMatches = regExpression.Execute(strNewContents)
    If colMatches.Count > 0 Then
    	For Each objMatch In colMatches
    		strValue = objMatch.Value
			strReplaceValue=Split(strValue,"""=""")(1)
			if Len(strReplaceValue)>0 then
				strReplaceValue=Left(strReplaceValue, len(strReplaceValue)-1)
				strCloneContents=Replace(strCloneContents,strDefault,strReplaceValue)
			end if
    	Next
    Else
    	strValue = ""
    End If
'MsgBox "Replacing User: " & strDefault & ", with user: " & strValue
Next
 
strContents = Replace(strContents, "Clone User", strNewUser)
strContents = Replace(strContents, "Clone Company", strNewCompany)
Set objCloneRegFile = objFSO.CreateTextFile("C:\DRIVERS\UCUPDATE\processed.reg", True, intUniCode)
objCloneRegFile.Write strCloneContents
objCloneRegFile.Close
Set objCloneRegFile = Nothing
 
================clone.reg (Manually created)================
Windows Registry Editor Version 5.00
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\.NETFramework\1.1\S867460]
"InstalledBy"="Clone User"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\MSXML4SP2\Q936181]
"InstalledBy"="Clone User"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Registration]
"NAME"="Clone User"
"COMPAN"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\CyberLink\PowerDVD8]
"UserName"="Clone User"
"Company"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\0B79C053C7D38EE4AB9A00CB3B5D2472\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\0E23E40C6140D434FA9B96967D309AFE\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\4F57260AB42358E4596E782BDC274910\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\6030E61781384634B8F8C04C9E73B6CA\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\68AB67CA330100007706010000000020\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\68AB67CA7DA73301B7448A0100000030\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\8A0F842331866D117AB7000B0D610007\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\9040110900063D11C8EF10054038389C\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\9040150900063D11C8EF10054038389C\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\90401A0900063D11C8EF10054038389C\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\9040B30900063D11C8EF10054038389C\InstallProperties]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\InstallShield_{2BF2E31F-B8BB-40A7-B650-98D28E0F7D47}]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\InstallShield_{6BE2A4A4-99FB-48ED-AE1E-4E850389F804}]
"RegOwner"="Clone User"
"RegCompany"="Clone Company"
 
[HKEY_LOCAL_MACHINE\SOFTWARE\PowerQuest\PartitionMagic\8.0\UserInfo]
"Name"="Clone User"
"Company"="Clone Company"
 
"RegisteredOwner"="Clone User"

Open in new window

Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, thanks for the grade.

You can easily get rid of the batch file (seeing as it really only runs two commands), by using the WScript.Shell object to execute those commands for you, one at the top of the VBS, the other at the bottom.

Rob.
Set objShell = CreateObject("WScript.Shell")
strCommand = "REG EXPORT ""HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"" C:\DRIVERS\UCUPDATE\new.reg"
objShell.Run strCommand, 1, True
 
strCloneRegFile = "C:\DRIVERS\UCUPDATE\clone.reg"
strNewRegFile = "C:\DRIVERS\UCUPDATE\new.reg"
 
'Array configuration Is
'<Field Name>;<Default Value in Clone File>
arrFields = Array(_
	"RegisteredOrganization;Clone Company", _
	"RegisteredOwner;Clone User" _
	)
 
Set regExpression = New RegExp
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Const intUniCode = -1
 
Set objCloneRegFile = objFSO.OpenTextFile(strCloneRegFile, intForReading, False, intUniCode)
strCloneContents = objCloneRegFile.ReadAll
objCloneRegFile.Close
Set objCloneeRegFile = Nothing
 
Set objNewRegFile = objFSO.OpenTextFile(strNewRegFile, intForReading, False, intUniCode)
strNewContents = objNewRegFile.ReadAll
objNewRegFile.Close
Set objNewRegFile = Nothing
 
For Each strFieldAndDefault In arrFields
	strField = Split(strFieldAndDefault, ";")(0)
	strDefault = Split(strFieldAndDefault, ";")(1)
	
	
	With regExpression
	    .Global = True
	    .IgnoreCase = true
	    'Match a space (\s)
	    .Pattern = """" & strField & """="".*"""
	End With
	
    Set colMatches = regExpression.Execute(strNewContents)
    If colMatches.Count > 0 Then
    	For Each objMatch In colMatches
    		strValue = objMatch.Value
			strReplaceValue=Split(strValue,"""=""")(1)
			if Len(strReplaceValue)>0 then
				strReplaceValue=Left(strReplaceValue, len(strReplaceValue)-1)
				strCloneContents=Replace(strCloneContents,strDefault,strReplaceValue)
			end if
    	Next
    Else
    	strValue = ""
    End If
'MsgBox "Replacing User: " & strDefault & ", with user: " & strValue
Next
 
strContents = Replace(strContents, "Clone User", strNewUser)
strContents = Replace(strContents, "Clone Company", strNewCompany)
Set objCloneRegFile = objFSO.CreateTextFile("C:\DRIVERS\UCUPDATE\processed.reg", True, intUniCode)
objCloneRegFile.Write strCloneContents
objCloneRegFile.Close
Set objCloneRegFile = Nothing
 
strCommand = "REG IMPORT C:\DRIVERS\UCUPDATE\processed.reg"
objShell.Run strCommand, 1, True

Open in new window

Avatar of RobSampson
RobSampson
Flag of Australia image

Oh, and thanks Purple for making the modifications...I was asleep while all that was going on!  :-P

Rob.
VB Script
VB Script

VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.

39K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo