How can I import registry keys using VBS?
Good morning,
I have a vbs script to install AutoTable 2014 for AutoCAD 2014.
The software installs with no problem at all.
My trouble is this script is not importing the registry key. I can log into the target machine as admin. Open a command prompt, and import the key with "regedit.exe /s [\\UNC\to\Registry\Key].reg"
The key is imported as expected. Why isn't this working when I push it with my k1000?
Additional Information:
I attach the script as a dependency to a kScript.
The Enabled checkbox is checked.
My intended machine is selected in Deployment section.
Run As User: Domain Admin
Allow Run While Logged Off checkbox is checked.
Verify:
Always Fail
Remediation:
Launch "C:\Windows\System32\cscript.exe" with params "$KACE_DEPENDENCY_DIR)\Install_AutoTable_for_ACAD_2014.vbs"
- ' Bullet Catcher
- ' Install_AutoTable_for_ACAD_2014.vbs
- ' this script is designed to install AutoTable for AutoCAD 2014. The script then applies licensing as needed.
- ' this script will install both AutoTable for ACAD 2014 as well as AutoTable for ACAD LT 2014
- ' ***** Variable Dictionary *****
- ' objFSO = used to determine if certain files exist on the host machine.
- ' objNetwork = gets computer name of current host machine.
- ' objShell = Windows shell object used to install the AutoTable 2014 executable file.
- ' execute_command = command line to carry out a specified command
- ' computer_name = Name of the host computer. Used to determine what license to apply to the AutoTable installation
- ' install_file = Command line for the AutoTable executable file.
- ' reg_file = The registry key to be imported that contains the licensing information.
- set objFSO = CreateObject("Scripting.FileSystemObject")
- set objNetwork = WScript.CreateObject("WScript.Network")
- Set objShell = WScript.CreateObject ("WSCript.Shell")
- execute_command = "cmd /c "
- computer_name = objNetwork.ComputerName
- ' Command line to install AutoTable 2014.
- install_file = """[UNC to]\AutoTable54-for-AutoCAD2014-x64.exe ""/VERYSILENT /NORESTART /LOG /SUPPRESSMSGBOXES"
- ' Verify ACAD 2014 or ACAD LT 2014 is installed by looking for the respective .exe
- if objFSO.FileExists ("C:\Program Files\Autodesk\AutoCAD 2014\acad.exe") Or objFSO.FileExists ("C:\Program Files\Autodesk\AutoCAD LT 2014\acadlt.exe")Then
- ' Determine license to apply based on computer name.
- Select Case computer_name
- case "LIST 1", "OF", "COMPUTER", "NAMES"
- reg_file = """[UNC to]\AutoTable_for_ACAD_2014_License_41_seats.reg"""
- case "LIST 2", "OF", "COMPUTER", "NAMES"
- reg_file = """[UNC to]\AutoTable_for_ACAD_2014_License_5_seats.reg"""
- case "LIST 3", "OF", "COMPUTER", "NAMES"
- reg_file = """[UNC to]\AutoTable_for_ACAD_2014_License_3_seats.reg"""
- case "LIST 4", "OF", "COMPUTER", "NAMES"
- reg_file = """[UNC to]\AutoTable_for_ACAD_2014_License_1_seat.reg"""
- case "LIST 5", "OF", "COMPUTER", "NAMES"
- ' Change the install_file to install AutoTable for AutoCAD LT 2014
- install_file = """[UNC to]AutoTable53-for-AutoCADLT2014-x64.exe ""/VERYSILENT /NORESTART /LOG"
- reg_file = """[UNC to]\AutoTable_for_ACAD_LT_2014_License_5_seats.reg"""
- End Select
- End if
- ' After determining proper license information, verify AutoTable is not already installed.
- if objFSO.FileExists ("C:\Program Files\Cadig\AutoTable\2014\WhatsNew.txt") then
- 'wscript.echo "AutoTable 2014 INSTALLED."
- else
- ' if not installed, install AutoTable 2014
- 'wscript.echo "AutoTable 2014 not installed."
- objShell.Run execute_command & install_file, 0, TRUE
- end if
- ' Import the appropriate registry keys to apply licensing
- objShell.Run execute_command & "regedit.exe /s " & reg_file, 0, True
1 Comment
[ + ] Show comment
Answers (1)
Please log in to answer
Posted by:
SMal.tmcc
10 years ago
the kace client is 32 bit so the script is running in 32 bit mode. so when you try the merge the registry it is probaly working just the keys are going to HKLM\software\wow6432node\...etc not HKLM\software\...etc like you expect. check under there and if they are there change your reg merge file lines to hklm64 instead of hklm
HKLM\software\wow6432node\...etc
Comments:
-
There are no AutoTable 2014 keys at HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cadig
When I import the keys locally they are imported as expected to HKEY_LOCAL_MACHINE\SOFTWARE\Cadig\Cadig2014\AutoTable - anonymous_95342 10 years ago-
that means the sysnative redirection was not the problem then
here is a variation on the way to do this in vbs, they add the other characters, and that may matter & Chr(34)
http://myitforum.com/cs2/blogs/dhite/archive/2006/09/01/Using-Vbs-To-Silently-Import-Reg-Files.aspx
http://social.technet.microsoft.com/Forums/en-US/033ac3b9-c6c7-46fd-b0b6-decd8ad497fa/vbscript-import-registry-file - SMal.tmcc 10 years ago-
Thanks for the info. But I was still not successful.
I have the script pushed through kBox, AutoTable installs but the reg key wont import. I can manually run the vbs file and it all works as expected.
Im having a hard time understanding how the kBox does it differently? - anonymous_95342 10 years ago
If the script executioin is set to execute in the logged-in user's context, then it's likely (hopeful, even, given where it's trying to write!) that the user has no write access to HKLM.
Of course, if your script had logging, you'd see all of this information. Seek out and use the rather excellent clsLog.VBS which makes adding logging to VBS a no-brainer.
EDIT:
Here...I saved you the trouble: http://www.visualbasicscript.com/m24797-print.aspx - anonymous_9363 10 years ago