Modify Text/Batch/Registry Files For Automation

So let’s say you are working with Batch Files or Regsitry files and you want to automate so sort of process to prompt a user for an input box and change values.

We have a registry file that contains the following information that we want to change.
Make sure that you set the text you want to change to strings that aren’t anywhere else in the file or else you will make changes to multiple items so don’t just change a “Y” to something else.

Windows Registry Editor Version 5.00

First we will start with a input box for SiteID, PhoneNumber and TerminalID

	set objShell = CreateObject("Wscript.Shell")
	Set objFSO = CreateObject("Scripting.FileSystemObject")

	SiteID = InputBox("Please Enter SiteID", "Site ID","")
	PhoneNumber = InputBox("Please Enter PhoneNumber in the following format xxx-xxx-xxxx","Phone Number","xxx-xxx-xxxx")
	TerminalID = InputBox("Please Enter TerminalID","Terminal ID","")

You can add protection around the input boxes so you have to enter a minimum amount of characters or must be numeric and have a specific amount of digits if you need.
This would be easier to accomplish by specific functions but let’s talk about that some other time.

Now let’s update our registry file before we merge it or deploy it.
First we point to our registry file

File = "C:\yeshaib.reg"

Now we will open the file and read the content, look for specifc strings and replace them.

Const ForReading = 1
Set objFile = objFSO.OpenTextFile(File, ForReading)
MyString = objFile.ReadAll()

MyString = Replace(MyString, "PPP-PPP-PPPP", PhoneNumber, 1, -1, 1)
MyString = Replace(MyString, "XXXX", SiteID, 1, -1, 1)
MyString = Replace(MyString, "TID", TerminalID, 1, -1, 1)

Set objFile = objFSO.CreateTextFile( File, True)
objFile.Write MyString

Run the script and it will prompt you three times




And the Registy file will have the correct changes

Windows Registry Editor Version 5.00

This entry was posted in Scripting and tagged , , , . Bookmark the permalink.