Basic KIX Login Script for Citrix Users

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 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

 

Join the conversation

35 comments

Send me notifications when other members comment.

Please create a username to comment.

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.
Cancel
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* :)
Cancel
This message was originally posted by Ron Oglesby on June 16, 2004
We can use it. As long as its not made in France.
Cancel
This message was originally posted by an anonymous visitor on June 14, 2004
www.respowerfuse.com
Cancel
This message was originally posted by Anon on June 11, 2004
This is nice but pretty simple...
Cancel
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.)
Cancel
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...
Cancel
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
Cancel
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.
Cancel
This message was originally posted by an anonymous visitor on June 16, 2004
Cancel
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%
Cancel
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.
Cancel
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.

Cancel
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.
Cancel
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.
Cancel
This message was originally posted by let me know on October 7, 2004
What needs to be installed on a workstation to run or create a kix script ? If I need to run a kix script on a server. what needs to be installed on the server ?
Cancel
This message was originally posted by Citrix44u on October 26, 2004
You dont need to install anything. You only need to call the kix32.exe. I Place the kix32.exe in the netlogon folder and call the scripts like this
%logonserver%\netlogon\kix32.exe %logonserver%\netlogon\logon.kix.

And thanks Ron for this script - There are some nice ideas!
Cancel
This message was originally posted by French Guy on November 4, 2004
thanks ron for your script!
you seem to be a great IT guy, but your comment about "We can use it. As long as its not made in France." shows a poor minded man.
i imagine your answer if an arabic or afghan ask you a tip!!
Well i guess us french we dont have to receive any lesson from you.
Have tour on your country history you will find what frenh brought to the USA.
guess it was just a silly joke
regards
Cancel
This message was originally posted by Sven sTian on November 9, 2004
That's what I was looking for.
setdefaultprinter("\\RAFS1\HP LaserJet 4500")

Now it's default black&white for all users :o)
Cancel
This message was originally posted by an anonymous visitor on December 6, 2004
I have written scripts using WMI that runs on every Windows OS except 3x. The scripts read the registry Run Keys and based on a comparsion of Run Keys and a SQL table with known Viruses and Spyware Run Key Names and it deletes the bad ones. Which prevents these apps. from starting up, this works on about 99% of the bad stuff.
Cancel
I'm not sure if the problem is with my path to the OUTLOOK.EXE or with the if/then command. Here is what I have:

***********************************

$OTLK = ReadValue ("HKEY_CURRENT_USER\Software\RapidApp","Otlk")
IF $OTLK<>1
Run "c:\Program Files\Microsoft Office\Office11\Outlook.exe /ImportPRF

c:\admin\scripts\CUSTOM.PRF"
WriteValue("HKEY_CURRENT_USER\Software\Rapidapp","Otlk",

"1", "REG_SZ")
ENDIF

***********************************

If I go to a dos prompt and change directory that I'm in to the OFFICE11 and run the outlook.exe with the switches above it runs perfectly but I can't seem to get it to work from within the login script. I've tried both the path above and this format:

Run "c:\Progra~1\Micros~1\Office11\Outlook.exe /ImportPRF c:\admin\scripts\GASSERV.PRF"

I'm dying to get this working can anyone help me? Thanks in advance!
Cancel
ORIGINAL: Guest

I'm dying to get this working can anyone help me? Thanks in advance!



Try this instead:

Run "c:\Program Files\Microsoft Office\Office11\Outlook.exe" /ImportPRF c:\admin\scripts\CUSTOM.PRF

Shawn
Cancel
I'd like to know how you keep the sql table up to date with all the latest viral strains.
And a copy of your code.
That would be sooooo awesome.
Cancel
"c:\Program Files\Microsoft Office\Office11\Outlook.exe" /ImportPRF c:\admin\scripts\CUSTOM.PRF
Cancel
Yeah and when the S*** hits the fan again in France, guess who will come to YOUR rescue. Let the Germans have you next time. Sorry folks, I have a bad taste for France politics, not its people.
Cancel
i would like a script to run when connecting to citrix > that determines connecting users current locale setting on their pc> and passes that value to his citrix session at login on the citrix server. Any ideas???- we cant use different scripts for different groups because we have groups with members in different countrys?
Cancel
I use KIX scripts for all the installations I do.  Most of the scripts I write are well over 1000 lines long, with a nice progress GUI, and they only take less than 5 seconds to run. KIX is way much faster and easier than VBScript. Mike
Cancel
time consuming, and messy.  There are cost effective tools out there like [link=http:
Cancel
time consuming and messy...interesting.  the truth is, if you know what your doing, time consuming and messy are the exact opposites of what you get.  as well, scripting is much more powerful than those tools ever will be.
Cancel
Scripting is cool and I do it but it creates a dependency when you are in a large company.  They don't want scriptmonkeys to create complex scripts for job security.  An open tool makes the work more transparent.

I believe in make scripting work only necessary to fill holes the tools don't perform but not just for everything.
Cancel
Thank you for this valuble info. very helpful for newbs to kixTart!!! Thanks!
Cancel
Depends on the scripter and the script needed.  GPO's and scripts are not easy or scaleable and a different approach must be taken for different app environments. If you have a GUI interface to do this and document this then why write a script?   Most everyone has two legs to walk with, but most use them to push the gas pedal of their vehicle to get to work - Go Gui, Go PowerFuse
Cancel
I import the PRF using VBScript, no need to run the Outlook.EXE to do it.  Here's how:
 
http://forum.chimera.co.nz/viewtopic.php?p=545
 
Cancel

Can't map drive if only open applications not the desktop, any suggest ?I using citrix PS 4.5 and program neighborhood client. 


Cancel

If you cant control your script monkeys (by implementing documentation policies), you shouldnt be a manager!  Good documentation means more portable employees (among other things)


Cancel

-ADS BY GOOGLE

SearchVirtualDesktop

SearchEnterpriseDesktop

SearchServerVirtualization

SearchVMware

Close