Category Archives: VBScript

ICA Client Detection #VBScript

Tags :

Category : VBScript

With a few lines of VBScript you can check if an ICA Client is installed and, if yes, determine its version.

If you only want to display the version information you can use the ICA Client Object’s AboutBox method:

This works for ICA Client Version 8 or newer.

Another approach uses the ICA Client Object’s ClientVersion property. The function below, GetICAClientVersion, returns the ICA Client’s version as a string:

How To Attach A Citrix Load Evaluator? #VBScript

This article provides the script AttachLoadEvaluatorToServer.vbs that attaches a Load Evaluator to a Citrix terminal server. The script is proven in CPS 4.0 and 4.5 environments, and thanks to the hint of one of my fellows at Login Consultants it supports now the built-in Load Evaluators “Default” and “Advanced”.

Given that you have a Load Evaluator to put a terminal server in offline mode – that is a Load Evaluator with an according Scheduling rule to disable ICA logons – this script is useful for automated installation or maintenance tasks.

Since AttachLoadEvaluatorToServer.vbs automates a Citrix server configuration it’s no surprise that it requires MFCOM. Therefore you should it execute on a Citrix terminal server. You need to specify the computer name of a terminal server in the farm and the exact name of the Load Evaluator as arguments. Listed below some examples to clarify the usage of the script…

This one attaches the Load Evaluator “DisableIca” to the Citrix server “ctx01”:

To attach the Load Evaluator “Advanced” to the Citrix server that executes AttachLoadEvaluatorToServer.vbs type:

Below you find the listing of the script:

Active Directory Login Script Template #VBScript

The login script template provided in this article maps network drives and printers based on the user’s membership in so-called “map groups”. Since a map group delivers the information which resource should be mapped for its members, you hardly ever need to modify this script due to changes in the drive or printer mappings.

For each drive and printer mapping you need to create an according AD group that follows an naming convention. By default, a map group for a network drive begins with “MAP-DRV-“, and the prefix for a network printer map group is “MAP-PRN-“. (Both prefixes can be customized by changing the constants MAP_DRIVE_GROUP_PREFIX and MAP_PRINTER_GROUP_PREFIX in this script.)

In addition to follow the naming convention you have to specify the network resources that should be mapped in the description field of a map group. In case of the map group for a network drive you must specify the drive letter followed by the unc path (seperated by a space character). In case of the printer map group you must specify the network printer’s unc path.

Since the script recognized indirect or nested group memberships you are able to add users as well as groups to the map groups. The LoadGroups function contains slightly modified code that I found on Richard L. Mueller’s website (, Thanks.

How To Retrieve The UUID/GUID From A Computer? #VBScript

Tags :

Category : VBScript

The VBScript function below, GetUUID, shows how to retrieve the UUID/GUID from a computer.

How to Set The Working Directory for WScript.Shell Run Method? #VBScript

Tags :

Category : VBScript

The Run method uses always the current working directory. Therefore, you have to change the directory if the command that will be executed with the Run method requires to be run from a specific directory.

The Sub below, RunHere, executes a command in the specified working directory and then changes back to the original directory.

How To Import a Regfile? #VBScript

Tags :

Batch programmers know that reg files can be imported silently with Regedit.exe /S.

This example shows how to implement this in VBScript:

It is worth to use a Sub-procedure, especially if you have to import more than one regfile.

How To Determine The Name Of The Local Administrator Group? #VBScript

Category : VBScript

The VBScript below, LocalAdminGroup.vbs, determines the name of the local administrator group by searching its SID in the list of local groups.

See also: Well-known security identifiers in Windows operating systems

How to Call a VBScript Within a #VBScript?

There are two ways of calling a second script (another script file), each with its advantages and disadvantages…

Run method

If you don’t need to share code and/or variables you can call the second script using the Run method.

Though you can’t share variables you can use command line arguments in order to transfer information.

Using this method you can call a JScript file too.

ExecuteGlobal statement

You can read the second script into a variable and pass it to ExecuteGlobal. This enables you to share code and variables.

The procedure below loads the second script on the fly and executes it with ExecuteGlobal.

Imprtant notes:

1. This method complicates debugging if an error occurs in the second script because you will get the line number of the ExecuteGlobal statement in the first script.

2. The first and the second script share the same namespace. Therefore, watch for unique variable and procedure naming.

How To Make My Script Terminal Server Aware? #VBScript #Batch

In order to detect if a script was started in a terminal server session the script can check the SESSIONNAME environment variable which is only defined if the Terminal Services are installed on Windows 2000 Server, Windows Server 2003, and Windows XP clients (or newer). When a client connects via a RDP or ICA (Citrix) session, this variable is a combination of the connection name, i.e. “RDP-Tcp” or “ICA-Tcp”, followed by a pound symbol “#” and then the session number in three figures “nnn“. When logging on directly to the machine, this variable returns “Console”.

The VScript function below returns True if the SESSIONNAME variable resolve to a value beginning with “RDP” or “ICA”

Terminal Server aware batch files can use this approach:

How To Show The End Of a Text File (Tail)? #VBScript

Tags :

Category : VBScript

The VBScript file below, Tail.vbs, shows the end (the last lines) of a text file.

During the read of the text file, instead of counting the lines, each line is pushed into a small, rotating stack held in a dynamic array (size = number of tail lines). At the end of file, the stack array is popped to echo the tail.