Solved Have a registry file enter the computers name as the data

March 7, 2013 at 13:36:42
Specs: Windows XP/7
I've exported some registry entries for a program which I wish to use on multiple pcs. The code has the computers name stated in it and of course each PC has a different name. I need to know how I can get this registry file to enter the Computer it's being run ons name as the value. Anyone got any insight?

See More: Have a registry file enter the computers name as the data

Report •

#1
March 7, 2013 at 17:39:43
This might help, but I'm sure there are better ways:
'==== begin vbscript
set fso=createobject("scripting.filesystemobject")
set wshell=createobject("wscript.shell")
a=wshell.expandenvironmentstrings("%computername%")
'-- this is basically a constant?
target="USER-HP"
z=fso.opentextfile("export",1,,-1).readall
r=replace(z,target,a)
fso.opentextfile("export",2,true,-1).write r
'=== end vbscript
if your export was via reg query (ascii), just use zero as the last argument for both read and write operations.

Report •

#2
March 7, 2013 at 18:12:52
Sorry I should have passed this on with the question, a snippet of the code i have is:

[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\x]
"Dbname"="x"
"Description"="x"
"Driver"="XBaseMS"
"Option1"="No"
"Option2"="No"
"Dbhost"="USER-HP"

[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\x]
"Dbname"="x"
"Description"="x"
"Driver"="XBaseMS"
"Option1"="No"
"Option2"="No"
"Dbhost"="USER-HP"

[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\x]
"Dbname"="x"
"Description"="x"
"Driver"="XBaseMS"
"Option1"="No"
"Option2"="No"
"Dbhost"="USER-HP"

[HKEY_LOCAL_MACHINE\SOFTWARE\ProQuestMS\x]
"MajorVersion"="6"
"MinorVersion"="4"
"BuildNumber"="3"
"InstallFolder"="C:\\Program Files\\ProQuestMS\\x"
"AppDataFolder"="C:\\ProgramData\\ProQuestMS\\x\\"
"InstallType"="Standalone"
"ServerName"="USER-HP"

Basically where it stats "USER-HP" I want it to instead lookup/ the value to be the computers name.


Report •

#3
March 7, 2013 at 18:45:13
✔ Best Answer
Here's the line you would need to change:

target="export_origin_computername"

to:
target="USER-HP"

the registry-export name is currently hard-wired as "export", and the script needs to be run on the recipient machine to get the correct computer-name inserted. So, the basic steps would be: 1) copy your registry export over to the recipient, 2) copy the vbscript over to the recipient, 3) run the vbscript ON THE RECIPIENT, and 4) import the now-altered file "export" into the recipient's registry. There are also other ways, such as getting the target-computer's name onto the local machine as a variable, doctoring the export file using it, then exporting it to the remote machine.
The usage is simply:
cscript nnnn.vbs
When run on the secondary computer, the primary computer's name will be replaced (in file "export") with the secondary computer's name. hope this helps...


Report •
Related Solutions


Ask Question