Limited Logon Scripts for Terminal Servers

Columnist David Carroll answers a reader's question about a logon script that's causing problems with Windows NT Server 4.0, Terminal Server Edition (TSE).

David Carroll

November 23, 2000

3 Min Read
ITPro Today logo

Our company uses a general logon script for all our users in our single domain network. We have several Windows NT Server 4.0, Terminal Server Edition (TSE) servers with Citrix MetaFrame that provide remote access to corporate applications. The general logon script makes several changes that are a problem for our terminal servers. Our network users use Windows 2000, Win2K Pro, NT, and Windows 98/95. Can I have a limited logon script for my MetaFrame servers but not mess up any of the network users?

You can accomplish your objective by adding an IF statement to the general logon script to determine whether a terminal server or another type of workstation is hosting the session and conditionally execute code depending on the host.

The following check at the beginning of the logon script redirects the logon script when a user connects to a terminal server. The logon script determines the platform it's executing on by looking at the HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControl ProductOptions registry key. In this key, there are two values to look for:

ProductType, with possible values of

  • WinNT—Win2K Pro or NT Workstation

  • ServerNT—Member server or Win2K Server

  • LanManNT—Domain controller or Win2K Server

  • " " (null)—Win98 and Win95, which don't have a ProductOptions subkey and therefore don't return a value

ProductSuite, with possible values of

  • Terminal Server—Terminal server or a Win2K Server with Win2K Server Terminal Services

  • " " (null)—Win2K Pro, NT Workstation, Win98/95

In the following example, I use the ACRegL.exe utility, which comes with Terminal Services, to check the registry location.

@echo off"\Termserv1WTSRVapplication Compatibility ScriptsACRegL.exe"%Temp%ServerType.Cmd server"HKLMCurrentControlSetControlProductOptionsProductSuite" ""If ErrorLevel 1 Goto Cont0Echo[Place workstation logon script here]Goto Done:Cont0EchoEcho You are running a Terminal Server sessionEcho [Place terminal server logon script here] ...

ACRegL first needs a .cmd or .bat file to write a temporary variable to. The script above writes to %Temp%ServerType.Cmd. Then the script names the temporary variable "server." The script looks for the registry location and the value. The script checks to see whether the ProductSuite value isn't equal to null, in which case the user is running a terminal server session.

You can also check for other values and run different scripts for different values. For example, consider the following script:

@echo off"\Termserv1WTSRVapplication Compatibility ScriptsACRegL.exe"%Temp%ServerType.Cmd server"HKLMCurrentControlSetControlProductOptionsProductSuite" "" If ErrorLevel 1 Goto ts"\Termserv1WTSRVapplication Compatibility ScriptsACRegL.exe"%Temp%ServerType.Cmd server"HKLMCurrentControlSetControlProductOptionsProductType" "" If NOT ErrorLevel 1 Goto Win9xEcho[Place Win2K/NT Workstation/Server logon script here]Goto Done:tsEchoEcho You are running a Terminal Server session.Echo [Place terminal server logon script here] Goto Done:Win9x[Place Win9x logon script here]Goto Done:Done

This script runs one script for Win9x clients, another for terminal server, and another for all other client types.

Another possibility is to check environment values such as %WINSTATIONNAME%, %computername%, or %Clientname%. You can also check for a file or directory, such as CHNGUSER or WTSRV, that exists only on a terminal server. Consider the following script:

if A%computername%A == ATERMSERV1A goto TermServ[Place workstation logon script here]goto done:TermServ[Place terminal server logon script here] :Done

Notice that I placed the letter A before and after the variable and the name. This convention is necessary because Win9x workstations receive a syntax error when they log on to the domain and run their logon scripts because Win9x doesn't understand the IF statement. The other machines just add the letters to the name and still make the value equal. Be creative and have fun. There are a lot of ways to remedy your headache.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like