Example Start Session Scripts
Start session scripts cannot run interactively. A start session script runs in an environment created by Horizon View, and the script must obtain its input data from this environment. The input data is gathered from environment variables on the client computer.
For a list of similar variables, see “Client System Information Sent to View Desktops” in the VMware Horizon View Administration document. Note that start session variables have the prefix VDM_StartSession_ instead of ViewClient_. For example, the start session variable containing the client system’s IP address is VDM_StartSession_IP_Address.
You should ensure that a start session script validates the existence of any environment variable that it uses.
The following sample Visual Basic script writes all the environment variables being provided to the script into a file, so that you can see example data in your own environment:
Option Explicit
Dim WshShell, FSO, outFile, strOutputFile, objUserEnv, strEnv
 
strOutputFile = "c:\setvars.txt"
 
Set FSO = CreateObject("Scripting.fileSystemObject")
Set outFile = FSO.CreateTextFile(strOutputFile, TRUE)
outFile.WriteLine("Script was called at (" & Now & ")")
 
Set WshShell = CreateObject( "WScript.Shell" )
Set objUserEnv = WshShell.Environment("PROCESS")
For Each strEnv In objUserEnv
outFile.WriteLine(strEnv)
Next
 
outFile.Close
You might save the preceding sample script as c:\sample.vbs.
The following sample script tests the timeout functionality:
Option Explicit
WScript.Sleep 60000
The following sample script tests a non-zero exit code:
Option Explicit
WScript.Quit 2
 
Note Make sure your start session scripts run quickly.
If you set the WaitScriptsOnStartSession value in the Windows registry, your start session script must finish running before View Agent can respond to the StartSession message sent from View Connection Server. A long-running script is likely to cause the StartSession request from View Connection Server to time out. If a timeout occurs, View Connection Server tries to connect the user to another virtual machine (if the pool uses floating assignments) or, if no virtual machine is available, to reject the user’s connection request.
In addition, you should set a hard timeout for the script host operation so that, if a script does run too long, a specific error can be returned.