Use VBS to input data to a REG file and run it

I have a REG file that I use to config our Cisco Softphones. The REG file requires me to change one line of the code to the user who the account was created for. In our case, we use their SAM account name to create the account on the back end. In the attached file on line 38, I have to change the username in "HostName"="IPC-USERNAME" so in my case, it would look like "HostName"="IPC-prologic08" if I was setting it up for myself.

I am looking to automate this process by installing the software and running the REG file with the SAM Account name already pulled and inputted into the REG file. My guess is that I have to create this as a VBS. I am not sure how to do this but to summarize, it would be like this:

VBS finds the SAM Account name, inputs the name into line 38 of the REG file in the space that says USERNAME. VBS runs the REG file that imports the data to the registry. VBS deletes the REG file. User opens up the Softphone software and all the configurations are done. User can start using softphone immediately.

Is there an easy way to do this or an easier way to do this? I never tried importing data to a REG file. I am even wondering if its even necessary to have the REG file and maybe instead have just a VBS that does everything. Can anyone help with this request please?
HKLM-Config.reg
prologic08Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dany BalianCTOCommented:
you can manually generate the reg file instead of searching and replacing..
save the following in a vbs file.
sorry for not testing the code, i just wrote it on a mac.

Dim samaccount
samaccount = InputBox("Enter Sam Account") 
var fso = new ActiveXObject("Scripting.FileSystemObject")
var a = fso.CreateTextFile("c:\\HKLM-config.reg", true)
a.WriteLine("Windows Registry Editor Version 5.00")
a.WriteLine("")
a.WriteLine("[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cisco Systems, Inc.\Communicator]")
a.WriteLine("""SoftPhoneData""=""C:\\Program Files (x86)\\Cisco Systems\\Cisco IP Communicator\\""")
'continue all lines from reg file here.. don't forget to escape double quotations..
'then line 38
a.WriteLine("""HostName""=""" & samaccount & """")
a.WriteLine("""UseSetVolume""=dword:00000001")
'..continue the remaining of the file..
a.Close(); 'this will save the reg file..
'this will create a new file on c drive named HKLM-config.reg
'just double click it to import and if you want to automatically import the created reg file from the vbs then simply use:
Dim wShell
 Set wShell = CreateObject("WScript.Shell")
 wShell.Run "regedit /s c:\HKLM-config.reg",0,True

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
prologic08Author Commented:
Thank you for this mrdany. I was going through it and noticed you had a mix of VBScript and Jscript in there. I made some edits to get what I needed. Thank you very much for your assistance! Here is the code I ended with.

Dim objNetwork
Set objNetwork = CreateObject("WScript.Network")
set fso = CreateObject("Scripting.FileSystemObject")
set a = fso.CreateTextFile("c:\HKLM-config.reg", true)
a.WriteLine("Windows Registry Editor Version 5.00")
a.WriteLine("")
a.WriteLine("[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cisco Systems, Inc.\Communicator]")
a.WriteLine("""SoftPhoneData""=""C:\\Program Files (x86)\\Cisco Systems\\Cisco IP Communicator\\""")
'continue all lines from reg file here.. don't forget to escape double quotations..
'then line 38
a.WriteLine("""HostName""=""IPC-" & objNetwork.UserName & """")
a.WriteLine("""UseSetVolume""=dword:00000001")
'..continue the remaining of the file..
a.Close() 'this will save the reg file..
'this will create a new file on c drive named HKLM-config.reg
'just double click it to import and if you want to automatically import the created reg file from the vbs then simply use:
Dim wShell
 Set wShell = CreateObject("WScript.Shell")
 wShell.Run "regedit /s c:\HKLM-config.reg",0,True

Open in new window

0
prologic08Author Commented:
I appreciate your time and effort.
0
Dany BalianCTOCommented:
Glad to know it helped :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.