Case Study: KiXtart to FastTrack logon script conversion

Many of our customers are porting from KiXtart to FastTrack. This article is based on a case where a KiXtart script of 1031 lines was converted to a richer 251 line FastTrack script. We would like to thank Kawasaki for kindly allowing us to show part of their conversion work. The motivation for the conversion was that the existing scripts were unable to execute properly on Windows 7 and 64-bit machines.

The recommended approach when converting existing logon scripts is to re-implement print and share connections based on the Logon Script Samples article and install software based on the Installations article, if you have not handled it by a management system already. Once those are taken care of, there are always some snippets left of the old scripts that are not mainsteam problems. On this page, we have picked out the parts of the old KiXtart logon script that was not covered by the above articles.

KiXtart to FastTrack logon script conversion

Case Study Note

Case Studies are provided to FastTrack Software by customers and are provided as-is. All case studies are unedited except from in most cases having actual company name, domain names, account names and server names replaced by fictitious names from a fictitious company named Acme. Please use our Contact Form, if you are interested in submitting an anonymous case study.

Snippet 1: Salutation

The first lines in the KiXtart script prompts for a salutation of the user:
$Hour = SubStr(@TIME,1,2)

Select
Case $Hour < 12
  $Salutation = "Good Morning,"
Case $Hour >= 12 and $Hour < 18
  $Salutation = "Good Afternoon,"
Case $Hour >= 18
  $Salutation = "Good Evening,"
EndSelect

? $Salutation + " " + @FULLNAME

KiXtart logon script welcome

To do something similar with FastTrack, we would use a splash screen to let the user know that something is going on. The snippet to do so with the same logic could look like this:

Set Salute = Good Afternoon

If [Hour]<12 Then Set Salute = Good Morning

If [Hour]>=18 Then Set Salute = Good Evening

Splash [Var Salute],[UserFullName]

The result would look as shown below. The reason the background is different with a FastTrack script is because FastTrack Logon will force the wallpaper to be set at logon time.

FSH logon script welcome

Snippet 2: Internet Explorer Security Settings

The KiXtart script includes three sections to modify ActiveX internet security settings. One is listed here:
$ActiveXCheck1 = ReadValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2","1201")
If @ERROR = 0
  If $ActiveXCheck1 <> 0
    WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2","1201",0,"REG_DWORD")
    If @ERROR <> 0
      ? "Error Code is " + @ERROR
    endif
  endif
endif
The script overwrites the existing value only if the value is different, to avoid a costly write operation. In case of an error, the error code is prompted to the user, to be able to debug write problems.

To produce a functionally identical version with FastTrack, we do not need to factor in the existing value nor error handling. The WriteRegistry command will not actually write the value, if the value is already the same. And in general errors are handled by the build-in error handler, as described in the Getting Started Guide. Therefore we can get the exact same functionality by just issuing the WriteRegistry command without factoring these in:

WriteRegistry HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2\1201,0,REG_DWORD

Note that this case specifically could have been handled by group policies, but the snippet would generally apply to any registry write operation.

Snippet 3: Change the Internet Explorer start page for non-admins

When overruling the Internet Explorer home/start page by group policies, it applies to everyone in the policy. In typical scenarios, domain administrators are excluded from policies in general, but in this case, the safe solution is chosen, where the logon script only sets the home page for users that are not administrators:
If InGroup("Domain Admins") = 0
  WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main","Start Page","http://intranet.acme.com","REG_SZ")
EndIf
The same functionality with FastTrack can be done like this:

If Not UserIsAdmin Then SetHomePage http://intranet.acme.com

Note that the FastTrack version also sets the home page for Chrome and FireFox and the name of the domain admins group is not hardcoded, which is relevant because the name "Domain Admins" may differ on localized domains.

Snippet 4: Desktop icons

As an aid to the user, some desktop icons are created at logon time to restart the computer or contact the HelpDesk. The KiXtart listing looks like this:
wshShortcut("%userprofile%\desktop\Service Request.lnk","http://helpdesk.acme.local/HomePage.do",,,)
wshshortcut("%userprofile%\desktop\Restart PC.lnk","%windir%\system32\shutdown.exe","-r -t 10",,,,)

Function WshShortCut($path,$targetpath,optional $arguments,optional $startdir,optional $iconpath,optional $style)
  Dim $shell,$shortcut
  $shell=CreateObject("wscript.shell")
  If $shell
    $shortcut=$shell.createshortcut($path)
    If $shortcut
      $shortcut.targetpath=$targetpath
      If $arguments
        $shortcut.arguments=$arguments
      EndIf
      If $startdir
        $shortcut.workingdirectory=$startdir
      EndIf
      If $iconpath
        $shortcut.iconlocation=$iconpath
      EndIf
      If $style
        $shortcut.windowstyle=$style
      EndIf
      $shortcut.save
      $shortcut=0
    EndIf
    $shell=0
  EndIf
  Exit @error
EndFunction
The FastTrack version is similar to the first two KiXtart lines, as listed below. The main difference is that FastTrack hugely outnumbers the build-in commands in KiXtart and a native command to create a shortcut indeed exists in FastTrack, whereas the KiXtart script would have to rely on a COM implementation of such a command.

CreateShortCut [UserDesktopDir],Service Request, http://helpdesk.acme.local/HomePage.do

CreateShortCut [UserDesktopDir],Restart PC,ShutDown.exe,-r -t 10


Snippet 5: Determining location

The logon script has to set a registry key as a machine setting, as to where it is located. This information is used for other programs to query and also to control installed software. It has to be pointed out that for a FastTrack implementation, it is a much better solution to rely on IP scopes to automatically determine location, if possible. Please refer to this article for more information.

If the computer name does not start with "Xpemb", the location has to be set in the registry. If the value is not already set, a default value of "NotSet" is written to the registry, which is done in the external file "SetRegLoc.kix". Once passed this point, the user is asked by a couple of prompts, if the computer is located in one of the Consumer Products locations or the administration building. If the user does not answer yes to one of the questions, the user is logged off to be re-prompted.

To be able to handle that the registry key has to be set through a domain administrator account, the external scripts to set the key are spawned in a new process. The third party utility psexec is used to copy the files locally and execute the registry write script as the administrative user. This process could have been done with fewer script lines, but the original material is preserved in the listing below.
If Left(@HOSTNAME,5) <> "Xpemb"
  $LocationValue = ReadValue("HKEY_LOCAL_MACHINE\Software\Acme","Location")
  If @ERROR <> 0
    shell '\\Acmedclcn001\SoftInst\psexec -u AcmeDom\svcSoftInst -p ####### -accepteula cmd.exe /C MD c:\lmtemp'
    copy "\\Acmedclcn001\SoftInst\psexec.exe" "c:\lmtemp\psexec.exe"
    copy "\\Acmedclcn001\NETLOGON\kix32.exe" "c:\lmtemp\kix32.exe"
    copy "\\Acmedclcn001\NETLOGON\setregloc.kix" "c:\lmtemp\setregloc.kix"
    shell 'c:\lmtemp\psexec.exe -u AcmeDom\svcSoftInst -p ####### -accepteula c:\lmtemp\Kix32.exe c:\lmtemp\setregloc.kix'
    del "c:\lmtemp\psexec.exe" /h
    del "c:\lmtemp\kix32.exe" /h
    del "c:\lmtemp\setregloc.kix" /h
    shell '\\Acmedclcn001\SoftInst\psexec -u AcmeDom\svcSoftInst -p ####### -accepteula cmd.exe /C RD c:\lmtemp /S /Q'
  endif

  $LocationValue = ReadValue("HKEY_LOCAL_MACHINE\Software\Acme","Location")
  If @ERROR = 0
    If $LocationValue <> "CP" and $LocationValue <> "ADM"
      $Selection = MessageBox("Is this computer physically located in a Consumer Products building?","Location Setup",4388)
      If $Selection = 6
        shell '\\Acmedclcn001\SoftInst\psexec -u AcmeDom\svcSoftInst -p ####### -accepteula cmd.exe /C MD c:\lm2temp'
        copy "\\Acmedclcn001\SoftInst\psexec.exe" "c:\lm2temp\psexec.exe"
        copy "\\Acmedclcn001\NETLOGON\kix32.exe" "c:\lm2temp\kix32.exe"
        copy "\\Acmedclcn001\NETLOGON\chgregloccp.kix" "c:\lm2temp\chgregloccp.kix"
        shell 'c:\lm2temp\psexec.exe -u AcmeDom\svcSoftInst -p ####### -accepteula c:\lm2temp\Kix32.exe c:\lm2temp\chgregloccp.kix'
        del "c:\lm2temp\psexec.exe" /h
        del "c:\lm2temp\kix32.exe" /h
        del "c:\lm2temp\chgregloccp.kix" /h
        shell '\\Acmedclcn001\SoftInst\psexec -u AcmeDom\svcSoftInst -p ####### -accepteula cmd.exe /C RD c:\lm2temp /S /Q'
      Else
        $Selection2 = MessageBox("Is this computer physically located in a administrative building?","Location Setup",4388)
        If $Selection2 = 6
          shell '\\Acmedclcn001\SoftInst\psexec -u AcmeDom\svcSoftInst -p ####### -accepteula cmd.exe /C MD c:\lm2temp'
          copy "\\Acmedclcn001\SoftInst\psexec.exe" "c:\lm2temp\psexec.exe"
          copy "\\Acmedclcn001\NETLOGON\kix32.exe" "c:\lm2temp\kix32.exe"
          copy "\\Acmedclcn001\NETLOGON\chgreglocadm.kix" "c:\lm2temp\chgreglocadm.kix"
          shell 'c:\lm2temp\psexec.exe -u AcmeDom\svcSoftInst -p ####### -accepteula c:\lm2temp\Kix32.exe c:\lm2temp\chgreglocadm.kix'
          del "c:\lm2temp\psexec.exe" /h
          del "c:\lm2temp\kix32.exe" /h
          del "c:\lm2temp\chgreglocadm.kix" /h
          shell '\\Acmedclcn001\SoftInst\psexec -u AcmeDom\svcSoftInst -p ####### -accepteula cmd.exe /C RD c:\lm2temp /S /Q'
        Else
          $selection3 = MessageBox("Please try again!!! " + @CRLF + @CRLF + "You must choose that this pc is located in either CP or ADM, you will now be logged off this pc." + @CRLF + @CRLF + "When you log in next time please choose the appropriate option.", "Location Setup", 4384)
          LogOff(1)
        Endif
      Endif
    Endif
  Endif
EndIf
For the FastTrack version, it is not necessary to copy any files locally first, because all logon script files are already running on a locally cached copy of the files, as this is done automatically by FastTrack Logon. To prompt the user for a location, the ListMenuForced is used to ensure that the user actively chooses a location:

If Not StartsWith [ComputerName],xpemb Then

  Set Selection=[ListMenuForced Select computer location,CP|Consumer Products,Adm|Administration]

  Run [FastTrackExe],/S ChangeLocation.fsh /P NewValue=[Var Selection],AcmeDom\svcSoftInst,5JTJbHIa1fabqoPv+5okEQ==

End If

The ChangeLocation.fsh elevated script looks like this, where a command-line parameter is used for the value. This also ensures that more locations can just be added to the calling script without having to change anything in the elevated script.

WriteRegistry HKLM\Software\Acme\Location=[CmdParam NewValue]

When the user logs on, the user will see the below. The previous location could have been pre-selected by reading the current value into the variable "Selection" before showing the menu.

FSH logon script welcome

Next step...

Go to www.fasttracklogon.com for instructions how to set up a logon script.



Rating: 5 out of 5

"Use this as a replacement for VBScript and PowerShell"

"It's easy to include attractive GUI elements in FastTrack scripts, beyond the basic dialog boxes and text input that VBScript offers ... Another powerful feature is the ability to distribute scripts as Windows Installer (.msi) or standard .exe files. Although interesting in its own right, this ability results in a much more intriguing capability: to repackage -- or wrap -- software installers as .msi files without using snapshots. If you've ever created an .msi installer file from before-and-after system snapshots, for use with a software distribution system such as Group Policy or SCCM, then you know how hit-and-miss the results can be."

Read full review


Rating: 8 out of 10

"Faster than the rest"

"We found the FastTrack syntax to be more transparent and easier to learn than Microsoft's PowerShell – the editor in particular provided good support in this regard. the Script Editor offers a large number of options from the command set through to simple output of graphical elements, which cannot be achieved at all with PowerShell or other solutions or only with a significantly greater level of effort."

"Anyone wanting to tackle the many hurdles in everyday admin and especially anyone for whom logon scripts and client automation is a priority will benefit from the variety of functions offered by FastTrack."

Review in English      Review in German