Skip navigation

KiXtart Scripting Basics

To make the best use of KiXtart, you should have a concept of the basic control constructs, variables, macros, commands, and functions that the tool uses. You can find more comprehensive information at or in the KiXtart documentation.

Control Constructs
Control constructs are the commands that control the flow of your scripts. Constructs permit certain commands or other scripts to be run, based on information provided in the script. For example, when you want a certain user to run a specific script, you can add the following If Else Endif control command to a script that every user runs.

If @USERID = "testuser"
Call "testusers.kix"

Every user runs the script, but only the user testuser will call the testusers.kix script that the If Else Endif control construct identifies. Other KiXtart control constructs include the following:

  • Do…Until—Continues to run a section of code until a certain condition is true.
  • While Loop—Continues to run a section of code while a certain condition is true. (Use caution with looping control constructs. If you aren't careful, you can create never-ending loops that will hang or crash the system.)
  • For Each—Runs a section of code for each item in an array or object.
  • For…Next—Runs code a preset number of times.

Variables provide the ability to store information in a descriptive label for your script to use. You then can use the variable and modify its value throughout your scripts. In KiXtart, all variables must begin with a dollar sign ($). The following example shows a variable put to use.

$strUserID = @USERID
? $strUserID

As with more advanced programming languages, KiXtart variables have a specific scope. A variable's scope determines whether subroutines or scripts called from within a script can see a variable that an earlier routine defined. You must understand the concept of variable scope when scripting. Improperly assigning a variable's scope can result in failed scripts or unknown results. The two types of scope are Global, in which any subroutine or script can see and alter the variable during the KiXtart session (i.e., during the logon process), and Local, in which the variable exists only in the subroutine or script that declared it. You can declare or create variables in several ways:

  • Implicit declaration—Simply assign the variable a value in the script. The previous example uses implicit declaration to declare the $strUserID variable. Implicitly declared variables have a global scope and can be seen throughout the scripting process.
  • Explicit declaration—Define a variable before giving it a value. To explicitly declare variables, use one of two commands: Dim or Global. The command you use determines the scope of the variable. Variables that you declare with the Dim command are local in scope and can be seen or used only in the current subroutine or script. The proper syntax for the Dim command is as follows:
Dim $variable

Variables that you declare using the Global command have a global scope and can be seen throughout the script execution. The proper syntax for the Global command is as follows:

Global $variable

Macros in KiXtart return information from the system running the script or from the network. These macros are similar to environment variables and shouldn't be confused with macros in products such as Microsoft Word, Excel, or Word Perfect. KiXtart macros aren't programs, and users can't modify them. All macros begin with the @ character. The following KiXtart macros are particularly useful:

  • @USERID—Returns the current user.
  • @LSERVER—Returns the server that performed the authentication for this logon.
  • @WKSTA—Returns the name of the workstation running the script.
  • @TIME—Returns the system time.

Commands perform an action. The following are some common commands:

  • Use—Maps drives or attaches to other network resources, such as printers.
  • Shell—Loads and runs a program. Standard batch commands are unavailable directly while running a KiXtart script, so KiXtart provides the ability to run standard batch commands and other programs through the Shell command. The program can be any 16- or 32-bit application. The KiXtart script stops and waits until the called program exits. Use care when calling an external program: If the called program hangs, so will the script.
  • Copy—Copies a data file.

Functions are similar to commands but return data. Typically, this data is stored in a variable. Sometimes the value is the status of the action that the function takes. For example, the ADDKEY() function adds a registry key and returns information that the key was added successfully or an error code that the addition was unsuccessful. Another example is the UCASE() function, which converts a string to uppercase. For example, to return the text HELLO, type


KiXtart contains some standard programming functions available in the majority of programming languages. In additional, KiXtart has specialized functions geared toward use in logon scripts on Windows 2000– or Windows NT–based network. One such function is the INGROUP() function, which evaluates whether the logged on user is part of the specified security group (and which cemented my love for KiXtart, incidentally). For example, the following code determines whether the current user is part of the Finance group, deletes any mapping to the G: drive, and remaps the drive to the Finance department share.

If INGROUP("Finance")
   Use g: /delete
   Use g: "\\servername\financeshare"

User-Defined Functions
KiXtart 2001 provides the ability to create user-defined functions (UDFs). Programmers are aware of the power and flexibility this enhancement provides. You can now create common modular routines that act on information you pass to them and return values as needed. To find out more about these new UDFs, refer to the KiXtart documentation.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.