I have managed to find the cause of the problem.

The printers are actually partially installing on first login. When you install the printers using AddPrinterConnection, Kixtart edits the registry Hkey_current_users\Printers\connections and a couple of other keys under Printers in the registry. For some reason it's not writing to the Connections key on first login most of the time.

What I need to do is tell kixtart to install the printer, then loop back and check that the registry setting has been applied and if not, wait 5 seconds and then re-install.

However, I was looking at the udf for this and I have three issues here. I seem to have a number of "if" statements without any "else" or "endif" statements. Can someone explain how that works as I don't understand why these if's don't require endifs.

Secondly, I am not sure how to tell the code to loop (install printer, then loop back and check printer was actually installed) without getting caught up in an if loop circle given the number of if statements I have here.

Third, I am probably misunderstanding this, but I have the Printer install part of the udf before the check if there is a free file handle. The second part of the udf I understand checks whether I can open the file and read the contents of the file and the first part of the udf is to actually read the contents of the file and install the printer based on the variables in that file. So it seems like the two parts are the wrong way around?

Here is the udf that I have:


;  Checks if printer is installed, and installs the correct printer based on area

Function PrintInstall($PrintFile) ;This part installs the printer

$Handle = Freefilehandle ()
 if $handle > 0
    if Open ($handle, $ServerName + "\setup printers\" + $Printfile) = 0
? $Servername
    $printsetup = Readline($handle)
       $ReturnCode = KeyExist("Hkey_Current_User\printers\Connections\,," + $PrintServer + "," + $printsetup)
 IF $ReturnCode = 1
 ? $printsetup + " Printer is already installed"
  ? "We need to install this printer " + $printsetup
AddPrinterConnection ($ServerName + "\" + $printsetup) ;I presume that I need to put the loop after this line and to loop back to  IF $ReturnCode = 1
 $printsetup = ReadLine($handle) ;This part checks if kixtart can open the file and read the contents
    IF Close($handle)
      ? "Error closing file!"
     ? "Unable to open" + $ServerName + "\setup printers\" + $PrintFile
  ? "Unable to obtain a free system handle."