This is what I call the “bees knees” of scripts for deploying VMware Tools. It will detect if it’s being installed on a Terminal/Citrix Server, and remove the appropriate components that may impede performance, etc.
I was initially using an old well know script to set the video acceleration. However, my friend Jamie Morrison, has written an even better one, which I’ve included as a function within this script. I also found a really nice PowerShell script for Setting Video Hardware Acceleration Level.
One of the tasks performed by the installation of VMware Tools is that it replaces the “Standard VGA Graphics Adapter” driver with the “VMware SVGA II” driver. It then detects if the Hardware Acceleration has previously been set to Full. If it hasn’t, it’ll prompt you with the following message box if using the /qb (quiet with a basic user interface) MSIEXEC switch.
On the other hand using the /qn switch disables the VM_CheckHWAcceleration action altogether. However, I try to avoid using the /qn switch for these sorts of things, as then you can’t see what’s going on when monitoring it from the console, etc.
So the trick is to set the Hardware Acceleration to Full before installing VMware Tools. Then, when it runs the detection mechanism by calling the VM_CheckHWAcceleration action within the MSI package, it will read back that it has already been set and complete the silent installation without any prompts.
Place the below InstallVMwareTools.vbs script in a folder, extracting the VMware Tools iso into a subfolder called ”VMware Tools”.
Note that the only line in the script you may want to change is the strLogLocation definition, which sets the location of the MSI log file. As you can see I place it in the “%SystemDrive%\bldlogs” folder.
The InstallVMwareTools.vbs is as follows:
' VMware Tools installation script.
' For Citrix/Terminal Servers, don't install VMware Tools components that can impede performance. These include:
' - MemCtl - Memory Control Driver (vmmemctl – reclaims memory using the balloon driver)
' - vmdesched - Descheduled Time Accounting (experimental)
' - Sync - Filesystem Sync Driver (LGTO_SYNC - can halt I/O disrupting services/users)
' - Hgfs - Shared Folders (vmhgfs – not supported on ESX)
' Version 1.1 released on 4th December 2008.
' Written by Jeremy@jhouseconsulting.com on 1st December 2008.
' The setVideoAcceleration function was written by Jamie Morrison (http://theether.net/)
Option Explicit
Dim objFSO, objFolder, wshShell, oShellLink, strScriptPath, strLogLocation, strOptions
Dim strCommandLine, strRegKey
set WshShell = WScript.CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")
strLogLocation = WshShell.ExpandEnvironmentStrings("%systemDrive%\bldlogs")
strScriptPath = GetCurrentPath
' Modifying the video hardware acceleration
If setVideoAcceleration Then
wscript.echo "Updated Video Hardware Acceleration to Full."
Else
wscript.echo "No Video Hardware Acceleration to set."
End If
' Building the MSIEXEC command line options
strOptions = " ALLUSERS=TRUE ADDLOCAL=ALL /Lv* " & chr(34) & strLogLocation & "\VMwareTools.Log" & chr(34) & " /qb- REBOOT=ReallySuppress"
If isTerminalServer Then
strOptions = strOptions & " REMOVE=" & chr(34) & "Hgfs,MemCtl,Sync,vmdesched" & chr(34)
End If
' Installing VMware Tools with the relevant command line options
strCommandLine = "msiexec /i " & chr(34) & strScriptPath & "VMware Tools\VMware Tools.msi" & chr(34) & strOptions
WshShell.Run strCommandLine,1,True
' If we are building a Citrix/Terminal Server, delete VMware Tools Tray Icon from the Run key.
' Note: There is also a setting for this in our Group Policy ADM template.
If isTerminalServer Then
strRegKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\"
If RegValueExists(strRegKey & "VMware Tools") Then
WshShell.RegDelete strRegKey & "VMware Tools"
wscript.echo "VMware Tools registry value deleted."
Else
wscript.echo "VMware Tools registry value does not exist."
End If
End If
Set WshShell = Nothing
WScript.Quit(0)
Function isTerminalServer
Dim strComputer, objWMIService, colItems, objItem
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_TerminalServiceSetting")
For Each objItem in colItems
Select Case objItem.LicensingType
Case "2"
isTerminalServer = True
Case "4"
isTerminalServer = True
Case Else
isTerminalServer = False
End Select
Next
Set objWMIService = Nothing
Set colItems = Nothing
End Function
Function GetCurrentPath
' Return path to the current script
DIM path
path = WScript.ScriptFullName
GetCurrentPath = Left(path, InstrRev(path, "\"))
End Function
Function setVideoAcceleration()
'
' SYNTAX: setVideoAcceleration()
'
' Parameters: N/A
'
' Returns: True if registry written successfully
'
' Example: setVideoAcceleration
'
' Remarks:
'
Const HKEY_LOCAL_MACHINE = &H80000002
Const VIDEO_LIST = "SYSTEM\CurrentControlSet\Control\Video"
Dim wbemLocator, wbemDefault, wshShell, regAllWMI, adapterList, adapterGUID, adapterPath, dwValue
Set wbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set wbemDefault = wbemLocator.ConnectServer(".", "root\default")
Set wshShell = WScript.CreateObject("WScript.Shell")
setVideoAcceleration = False
Set regAllWMI = wbemDefault.Get("StdRegProv")
If (Err.Number <> 0) Then
script.echo "Error connecting to WMI StdRegProv " & Err.Number & " : " & Err.Description
Else
regAllWMI.EnumKey HKEY_LOCAL_MACHINE, VIDEO_LIST, adapterList
If (Err.Number <> 0) Then
wscript.echo "Could not enumerate video adapters"
Else
For Each adapterGUID In adapterList
adapterPath = VIDEO_LIST & "\" & adapterGUID & "\0000"
regAllWMI.GetDWORDValue HKEY_LOCAL_MACHINE, adapterPath, "Acceleration.Level", dwValue
If Not IsNull(dwValue) Then
regAllWMI.SetDWORDValue HKEY_LOCAL_MACHINE, adapterPath, "Acceleration.Level", 0
setVideoAcceleration = True
End If
Next
End If
End If
Set regAllWMI = Nothing
Set wshShell = Nothing
Set wbemDefault = Nothing
Set wbemLocator = Nothing
End Function
Function RegValueExists(sRegValue)
' Returns True or False based of the existence of a registry value.
Dim oShell, RegReadReturn
Set oShell = CreateObject("WScript.Shell")
RegValueExists = True ' init value
On Error Resume Next
RegReadReturn = oShell.RegRead(sRegValue)
If Err.Number <> 0 Then
RegValueExists = False
End if
On Error Goto 0
Set oShell = Nothing
End Function
Enjoy!!!

Post a Comment