Tip: Kixtart example login script


NOTE: Error Code Reference:

June 11, 2004

This article is part of Ron Oglesby's Scripting for MetaFrame Series.

 

In this series of articles I focus on how an you can use scripting in a Terminal Server / Citrix MetaFrame environment for common and recurring tasks. This article covers the basics of using a KIX login script to configure your Citrix users’ environment.

 

As an administrator, you have a choice of many different scripting languages. My personal favorite (and the favorite of many Citrix admins) is KIX (available for free). While VBS has its place and is perfect for administrative tasks, KIX is the true king for logon scripts in MetaFrame. Its ease of use, the fact it’s a simple (and forgiving) language, and its focus on modifying the user’s environment make it perfect for MetaFrame and Terminal Server users.

 

Before we get into some of the common functions you’ll perform for the users, let’s start with some basic logic for your script. A really good practice is to break your script into two parts: initial user configuration and logon settings.

 

The first part of a KIX script is usually the initial configuration of the user. These are settings that your only need to run once if using roaming profiles or local profiles on a single server. Such settings might include:

 

The second part of the script is used for settings or processes that need to be run at each time the user logs on. These settings may include:

 

The reason I like to break these into two parts is for speed. While you could run both parts of the script every time the script is run, I like to run the “run once” type of settings only once. Basically I create a registry key for the user during the script and use version info to determine if they have run the latest version of the script. If they have, the script can skip the “run once” section. If they haven’t, they run the entire script and get the new settings. This allows you to speed up your logons a little, which is always important in a Citrix environment.

 

Okay, let’s move on to the script itself. First of all, you should keep a history of the script within it. The extra lines in the script won’t affect performance. I keep a simple version number at the beginning of my logon scripts:

 

;*************************************************************************

;************* logon.KIX configures the user's profile *****************

;************* Ver 1 Base Build. Outlook settings and printers   *****************

;************* Ver 1.1 disables the adobe splash screen    *****************

;************* Ver 1.2 disables autoload of IM *****************

;************* Ver 1.3 disables autoload of IM when Outlook is launched *****************

;************* Ver 1.4 Enables outlook to attach EXE and URL files **********

 

These numbers can then be used as the value for the registry key the script checks, and creates or modifies.

 

The first step in my script is to check for the current version of the script that this user has run:

 

$VER = ReadValue ("HKEY_CURRENT_USER\Software\RapidApp","Version")

 

This command sets the variable “$VER” equal to the value of a registry key by using a simple ReadValue command. The format for this command is as follows:

 

ReadValue (“Hive\key\subkey\subkey”,”Value you wish to read”)

 

It’s so simple it’s sick. I now know that the variable $VER is equal to the value set in the users’ registry location HKCU\Software\RapidApp\Version. At this point we can throw a quick IF in there to see if the user is current or not:

 

IF $VER=1.4

  GOTO ALWAYS

ELSE

  GOTO RUNONCE

ENDIF

 

Here we check to see if they have a value of 1.4. If they do I send them to the “ALWAYS” section of my script that runs each time a user logs on. If that registry value does not equal 1.4 then they run the next section (“RUNONCE”), then continue onto “ALWAYS”. (For brevity I have changed my scripts here and made them very simple to use. The scripts below may not represent the version descriptions above)

 

:RUNONCE

;*************************************************************************

 ; Outlook Config

 

  $OTLK = ReadValue ("HKEY_CURRENT_USER\Software\RapidApp","Otlk")

   IF $OTLK<>1

            Run "d:\Progra~1\Micros~1\Office10\Outlook.exe /ImportPRF D:\admin\scripts\Outlook.prf"

        WriteValue("HKEY_CURRENT_USER\Software\Rapidapp","Otlk", "1", "REG_SZ")

   ENDIF

 

Notice here that I check to see if their Outlook profile has ever been configured. If not I launching Outlook with an Import PRF switch. Most of my remote users use a desktop and this is a simple and easy way to do it. Another way to do this (in new versions of Office) is to simple set a key in a specific spot in HKCU for IMPORTPRF with a value of the location of the PRF. This will configure outlook to use the PRF file the first time they launch it too.

 

Continuing in the “run once” part of the script, I then begin to set some registry keys I need for certain applications. As you can see below I assume that the keys I want are not there so I create them then writing the value I want. The great thing about this is that if the key (folder) does exist the addkey will just fail and the script will continue on to write (or overwrite) the value I am importing.

 

 

 ;*************************************************************************

 ; Disable Splash screen for adobe reader ADDED WITH VER1.1

 

 AddKey("HKEY_CURRENT_USER\Software\ADOBE\Acrobat Reader\5.0\AdobeViewer")

 WriteValue("HKEY_CURRENT_USER\Software\ADOBE\Acrobat Reader\5.0\AdobeViewer","DISPLAYABOUTDIALOG", "00000000", "REG_DWORD")

 

 AddKey("HKEY_CURRENT_USER\Software\ADOBE\Adobe Acrobat\5.0\AdobeViewer")

 WriteValue("HKEY_CURRENT_USER\Software\ADOBE\Adobe Acrobat\5.0\AdobeViewer","DISPLAYABOUTDIALOG", "00000000", "REG_DWORD")

 

 ;*************************************************************************

 ; Disable the IM auto-loader ADDED WITH VER 1.3 and 1.4 for published apps

 

 DelValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "MSMSGS")

 AddKey("HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Outlook\IM")

 

 WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Outlook\IM","Enabled", "00000000", "REG_DWORD")

 

 ;*************************************************************************

 ; Enables a user to see and attach EXEs and URLs within outlook

 

WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Outlook\SECURITY\","Level1Remove", "exe;url", "REG_SZ")

 

;**************************************************************************

; Write the version info into the registry.

AddKey("HKEY_CURRENT_USER\Software\RapidApp")

WriteValue("HKEY_CURRENT_USER\Software\RapidApp","Version", "1.4", "REG_SZ")

 

Notice how the AddKey, WriteValue, ReadValue commands and syntax within KIX are simple and self-explanatory. Part of the appeal of KIX is that it is very simple to use but still offers great power for modifying the user environment. If you are going to use KIX I highly recommend getting the KIXtart.CHM file that is floating around on the internet. It’s a nice help file with samples for each command and function in KIX.

 

In addition, right at the end of the first section of the script I update the version info in the user’s registry. This is what allows us to limit its use and thus speed up the logon.

 

With all of the basic configuration and registry keys I want added to the user I now move onto my “ALWAYS” Section. This section will run every time regardless of version of the script. Here I map two drives (drives used by applications only run from Citrix), add two printers, set a default printer for users in my Chicago office, and I replace a file (and ini) in their home dir and put their Windows username in a specific value in the INI. This INI gets changed about every three days so I have found this a simple way to keep up with it.

 

 

 

:ALWAYS

 

;*************************************************************************

; Map drives for Citrix users.

 

    USE L: /DELETE

    USE K: /DELETE

    USE L: \\RAFS1\DOCs12

    USE K: \\RAFS2\DJQ

;*************************************************************************

; Set the 4000 and 4500 printers for the Chicago Users

 

IF INGROUP("CHIUsers")

    addprinterconnection("\\RAFS1\HP4000")

    addprinterconnection("\\RAFS1\HP4500")

    setdefaultprinter("\\RAFS1\HP LaserJet 4500")

ELSE

  ? "Non-Chicago User"

ENDIF

 

;*************************************************************************

; Copy the DOCs12.ini and modify username settings

 

COPY “\\RAFS1\Source\W2HCM.ini" "%homedrive%%homepath%\windows\DOCs12.INI"

 

WriteProfileString("%homedrive%%homepath%\windows\DOCs12.ini","Session","User")

 

:END

 

As you may have noticed I have no error handling in this script. Basically this script is so simple that not much is needed. But as you get more advanced and start creating more detailed scripts you may need to build in some error checking.

 

Anyway, basic KIX logon scripts are easy to do and allow you to do almost anything to the user’s environment. Here I’ve shown you how to map drives, read and write registry values, copy files, modify INI files, setup printers, check for group membership and even use version controls to speed up the logon process. Below is the complete sample script. Obviously there is much more you can do with KIX (MUCH more) and in a future article we will go into more detailed and interesting KIX scripts.

 

 

;*************************************************************************

;************* logon.KIX configures the user's profile    

;************* Ver 1 Base Build. Outlook settings and printers   

;************* Ver 1.1 disables the adobe splash  screen

;************* Ver 1.2 disables autoload of IM            

;************* Ver 1.3 disables autoload of IM  when  OutLook is launched  

;************* Ver 1.4 Enables outlook to attach EXE and URL files  

 

$VER = ReadValue ("HKEY_CURRENT_USER\Software\RapidApp","Version")

IF $VER=1.4

  GOTO ALWAYS

ELSE

  GOTO RUNONCE

ENDIF

 

 

 

:RUNONCE

;*************************************************************************

 ; Outlook Config

 

  $OTLK = ReadValue ("HKEY_CURRENT_USER\Software\RapidApp","Otlk")

   IF $OTLK<>1

            Run "d:\Progra~1\Micros~1\Office10\Outlook.exe /ImportPRF D:\admin\scripts\Outlook.prf"

        WriteValue("HKEY_CURRENT_USER\Software\Rapidapp","Otlk", "1", "REG_SZ")

   ENDIF

 

 

;*************************************************************************

 ; Disable Splash screen for adobe reader ADDED WITH VER1.1

 

 AddKey("HKEY_CURRENT_USER\Software\ADOBE\Acrobat Reader\5.0\AdobeViewer")

 WriteValue("HKEY_CURRENT_USER\Software\ADOBE\Acrobat Reader\5.0\AdobeViewer","DISPLAYABOUTDIALOG", "00000000", "REG_DWORD")

 

 AddKey("HKEY_CURRENT_USER\Software\ADOBE\Adobe Acrobat\5.0\AdobeViewer")

 WriteValue("HKEY_CURRENT_USER\Software\ADOBE\Adobe Acrobat\5.0\AdobeViewer","DISPLAYABOUTDIALOG", "00000000", "REG_DWORD")

 

 ;*************************************************************************

 ; Disable the IM auto-loader ADDED WITH VER 1.3 and 1.4 for published apps

 

 DelValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "MSMSGS")

 AddKey("HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Outlook\IM")

 

 WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Outlook\IM","Enabled", "00000000", "REG_DWORD")

 

 ;*************************************************************************

 ; Enables a user to see and attach EXEs and URLs within outlook

 

WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Outlook\SECURITY\","Level1Remove", "exe;url", "REG_SZ")

 

;**************************************************************************

; Write the version info into the registry.

AddKey("HKEY_CURRENT_USER\Software\RapidApp")

WriteValue("HKEY_CURRENT_USER\Software\RapidApp","Version", "1.4", "REG_SZ")

 

 

:ALWAYS

 

;*************************************************************************

; Map drives for Citrix users.

 

    USE L: /DELETE

    USE K: /DELETE

    USE L: \\RAFS1\DOCs12

    USE K: \\RAFS2\DJQ

;*************************************************************************

; Set the 4000 and 4500 printers for the Chicago Users

 

IF INGROUP("CHIUsers")

    addprinterconnection("\\RAFS1\HP4000")

    addprinterconnection("\\RAFS1\HP4500")

    setdefaultprinter("\\RAFS1\HP LaserJet 4500")

ELSE

  ? "Non-Chicago User"

ENDIF

 

;*************************************************************************

; Copy the DOCs12.ini and modify username settings

 

COPY “\\RAFS1\Source\W2HCM.ini" "%homedrive%%homepath%\windows\DOCs12.INI"

 

WriteProfileString("%homedrive%%homepath%\windows\DOCs12.ini","Session","User")

 

:END