Question : Editing multiple registry files WITH Hex numbers

Hi there,

I am curious if this is even possible... I have 300+ folders and each folder is named any 3 digit number from 100 to 984.  In each folder there are 2 files, one of them is a registry file sal_cp.reg.  One line for every store needs to be changed to the hex version of the store number (folder name).  For example:  In the folder '101', I open and edit sal_cp.reg and need to change "StoreNumber"=dword:00000000 to "StoreNumber"=dword:65 - 65 is the Hex form of 101.  Can this be done in a script?  Thanks
Code Snippet:
1:
2:
3:
[HKEY_LOCAL_MACHINE\SOFTWARE\MTXEPS\ServerEPS\Common]
"CompanyNumber"=dword:XXXXX
"StoreNumber"=dword:00000000
Open in New Window Select All

Answer : Editing multiple registry files WITH Hex numbers

Ok, sorry about that.  I neglected to take into account that .reg files are in Unicode format.  This version should work correctly.


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
Const ForReading = 1
Const ForWriting = 2
Const TristateTrue = -1
 
strFolder = "c:\files"
strComputer = "."
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 
Set colSubfolders = objWMIService.ExecQuery _
	("Associators of {Win32_Directory.Name='" & strFolder & "'} " _
		& "Where AssocClass = Win32_Subdirectory " _
			& "ResultRole = PartComponent")
 
For Each objSubfolder in colSubfolders
	strFile1 = strFolder & "\" & objSubfolder.FileName & "\cpInstall.ini"
		
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objTextFile = objFSO.OpenTextFile(strFile1, ForReading)
 
	Do Until objTextFile.AtEndOfStream
		strNextLine = objTextFile.Readline
 
		intLineFinder = InStr(strNextLine, "Desc=")
		If intLineFinder <> 0 Then
				strNextLine = "Desc=#" & objSubfolder.FileName
		End If
 
		intLineFinder = InStr(strNextLine, "Branch=")
		If intLineFinder <> 0 Then
				strNextLine = "Branch=" & objSubfolder.FileName
		End If
 
		strNewFile = strNewFile & strNextLine & vbCrLf
	Loop
 
	objTextFile.Close
 
	Set objTextFile = objFSO.OpenTextFile(strFile1, ForWriting)
 
	objTextFile.WriteLine strNewFile
	objTextFile.Close
	strNewFile = ""
	
	strFile2 = strFolder & "\" & objSubfolder.FileName & "\sal_cp.reg"
	
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objTextFile = objFSO.OpenTextFile(strFile2, ForReading, False, TristateTrue)
 
	Do Until objTextFile.AtEndOfStream
		strNextLine = objTextFile.Readline
 
		intLineFinder = InStr(strNextLine, Chr(34) & "StoreNumber" & Chr(34) & "=")
		If intLineFinder <> 0 Then
			strNextLine = Chr(34) & "StoreNumber" & Chr(34) & "=dword:" & Hex(objSubfolder.FileName)
		End If
 
		strNewFile = strNewFile & strNextLine & vbCrLf
	Loop
 
	objTextFile.Close
 
	Set objTextFile = objFSO.OpenTextFile(strFile2, ForWriting, False, TristateTrue)
 
	objTextFile.WriteLine strNewFile
	objTextFile.Close
	strNewFile = ""
Next
Open in New Window Select All
Random Solutions  
 
programming4us programming4us