Monthly Archives: September 2005

  • 0

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:


  • 1

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.


  • 0

How To Test WMI Connectivity? #VBScript

Tags :

Category : VBScript

The VBScript file below, WMIPing.vbs, checks if connection to WMI of the target system can be established.

WMIPing.vbs exits with an errorlevel:

  • 0 = WMI Ping succeeded successfully
  • 1 = ICMP Ping failed, WMI Ping omitted
  • 2 = WMI Ping failed


  • 0

How To Copy The Standard Output To a File (Tee)? #VBScript

Tags :

Category : VBScript

The VBScript file below, Tee.vbs, copies standard input to a file.

Basically, it reads a line from standard input (ie. WScript.StdIn) and writes it to both, standard output (WScript.StdOut) and a textstream object.


  • 1

How To Run A Process In A Hidden Window? #VBScript

Category : VBScript

The WScript.Shell‘s Run method executes the specified command line in a new process. Optionally you can specify an integer value that sets the appearance of the window. A value of 0 hides the window.

The VBScript file below, RunHide.vbs, demonstrates the usage of Run and creates a new process that executes in a hidden window.


  • 0

How To Determine an AD User’s GUID? #VBScript

The VBScript file below, ShowGUID.vbs, shows the current user’s GUID.

ShowGUID.vbs shows how to use ADSI‘s NameTranslate object.

More info on NameTranslate: NameTranslate FAQ


  • 0

How To Map Drives Based On an Active Directory Site? #VBSCript

You can use the ADSystemInfo object to determine the site name of the local computer:


  • 0

How To Script INI Files? #VBScript

Tags :

Category : VBScript

The VBScript file IniFileClass.vbs provides a VBScript class to read from and write to ini files.

Import and Usage

The following approach shows how to import and use the IniFile class with a WSH 2.0 .ws file:

If you still use WSH 1.0 or prefer .vbs files, you can include all the class file’s content at the top of a script or import the class file’s content using the VBScript 5.0 runtime evaluation function ExecuteGlobal as that shown below.

And finally, here comes the listing of IniFileClass.vbs


  • 0

How To Set MS Office 2003 User Information? #VBScript

Microsoft Office 2003 (and former versions) saves user information in the current user’s registry in REG_BINARY format (and not REG_SZ as one might expect.)

This article provides a VBScript script file, SetOff11Usr.vbs, that sets user information for Microsoft Office 2003 (11.0).

The script reads the AD user object’s properties givenname and sn in order to determine the user’s username and userinitials.

Due to a limitation (or call it bug) in the WSH’s RegWrite implementation with respect to REG_BINARY values the script uses WMI’s StdRegProv‘s SetBinaryValue method. SetBinaryValue expects the registry value’s data in array format. SetOff11Usr.vbs converts the string data to array using the function StringToArray:


  • 0

How To Check Existence Of a Registry Key? #VBScript

Tags :

Category : VBScript

If you want to check the existence of a registry key using the RegRead method it is no good idea to test on Err.Number because RegRead returns the same error number when trying to read

  • a non-existent key
  • a key’s non-existent default value

The approach below tests the Err.Description: