Brian Madden Logo
Your independent source for application and desktop virtualization.
Marketplace

advertisement

Basic KIX Login Script for Citrix Users

Written on Jun 11 2004 16,976 views, 35 comments


by Ron Oglesby

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:

  • Configuring the Outlook profile
  • Setting certain registry entries for applications
  • Copying a file into the user’s home directory

 

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:

  • Updating a file based on time or date for the user
  • Changing frequently modified registry entries or application settings to reflect new or modified values
  • Checking for and installing printers into the session
  • Mapping drives

 

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

 



Comments

Guest wrote Cool, how about something more complex?
on 12-12-2004 1:22 PM
This message was originally posted by Anon on June 11, 2004
This is nice but pretty simple...
Guest wrote Right its simple.
on 12-12-2004 1:22 PM
This message was originally posted by Ron Oglesby on June 11, 2004
Thats the point. But of course if you mean a simple script, yes it is, to those that can script. Anyway I might get more advanced in a lter kix article. Basically I am trying to ease into scripting here so people new to it can learn its not that hard.
Guest wrote Why hassle with scripting when you can use PowerFuse??
on 12-12-2004 1:22 PM
This message was originally posted by an anonymous visitor on June 14, 2004
www.respowerfuse.com
Guest wrote How much does PowerFuse cost?
on 12-12-2004 1:22 PM
This message was originally posted by an anonymous visitor on June 14, 2004
Exactly. That's why people script things. Why pay all that to do simple things you can do with a script. (I agree Powerfuse is good for complex stuff, but this script is simeple.)
Guest wrote One user cost you the same as scripting for one hour
on 12-12-2004 1:22 PM
This message was originally posted by an anonymous visitor on June 14, 2004
Becides, solving scripting issues is just one of the things PowerFuse are taking care of. If you kan build a solution where you can put the customer in to the front seat and handle the daily changes - you will get a happy customer. Start build good manageable deployments and you can easy defend the PowerFuse investment. Trust me...
Guest wrote Not just the complexity of the scripts, but the speed -
on 12-12-2004 1:22 PM
This message was originally posted by P Reid on June 14, 2004
AppSense Server based toolkit is the way forward - GUI based, but more importantly quicker than most scripts - I use all the time to allow printer mappings to be based on IP address - it rocks
Guest wrote www.respowerfuse.com
on 12-12-2004 1:22 PM
This message was originally posted by Ron Oglesby on June 15, 2004
funny response. sounds like someone works for the company. Thats cool. But believe me, everything has its place and share of customers. But also no one is ever going to say scripting doesn't have its place or more specifically a HUGE place in the Citrix market. There are a large numbers of small companies with admins out there that want to do these things. Lets not turn it into a add, its just meant to help out those guys wanting to do some things they dont know how to do now.
Guest wrote Totally agree Ron
on 12-12-2004 1:22 PM
This message was originally posted by an anonymous visitor on June 16, 2004
You will always need script for a lot of thing. PS: I dont work for RES, I'm just totally in love with the product. PowerFuse are doing great in Europe and I would guess that you guys in US also could use the product, even if it's not *made in US* :)
Guest wrote OK, ok, ok
on 12-12-2004 1:22 PM
This message was originally posted by Ron Oglesby on June 16, 2004
We can use it. As long as its not made in France.
Guest wrote LOL
on 12-12-2004 1:22 PM
This message was originally posted by an anonymous visitor on June 16, 2004
Guest wrote May also want to look at www.autoprof.com (profilemaker and policymakre)
on 12-12-2004 1:22 PM
This message was originally posted by IB on June 17, 2004
On key thing available with profilemaker is the ability to get detailed logging info in case your users start getting errors.
I use both- profilemaker to handle MS tweaks/setup, and KIX for almost everything else. In fact, I typically call ProfileMaker from KIX if I need it.
run %profmakerpath%\profmkr.exe /s %computername% /t %ProfMakerFlags%
Guest wrote vbscript is builtin and does it all
on 12-12-2004 1:29 PM
This message was originally posted by vbscript dude on June 24, 2004
The title says it all. I have yet to find anything that couldn't be done by some vbscripting.
Guest wrote Run Logon Script With A Published Application
on 12-12-2004 1:31 PM
This message was originally posted by Philip on August 19, 2004
The examples shown are really great.
If you run a Citrix published Application, how can you also run the logon script, as the script set's up various mapped drives etc.

Guest wrote VBScript Resource
on 12-12-2004 1:50 PM
This message was originally posted by an anonymous visitor on September 21, 2004
Does anyone have any useful sites for getting good vbscript, useful in logon scripts.
Guest wrote Kix versus vbscript
on 12-12-2004 1:50 PM
This message was originally posted by an anonymous visitor on October 5, 2004
I have been using kix scripts now for about 6 years. The main reason for using kix over vbscript is in fact the ease of making the scrips and SPEED.
Kix scripts is by far much faster than vbscripts.

For the small solutions this is not noticable, but for larger enterprises with really complex logonscripts, it is.