• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 774
  • Last Modified:

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
0
prologic08
Asked:
prologic08
  • 2
  • 2
1 Solution
 
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
 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now