Link to home
Start Free TrialLog in
Avatar of prologic08
prologic08

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Dany Balian
Dany Balian
Flag of Lebanon image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of prologic08
prologic08

ASKER

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

I appreciate your time and effort.
Glad to know it helped :)