#213699 - 2019-06-12 10:32 AM
Re: printers not showing on first login
[Re: Robdutoit]
|
Robdutoit
Hey THIS is FUN
 
Registered: 2012-03-27
Posts: 310
Loc: London, England
|
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)
WHILE @ERROR = 0
$ReturnCode = KeyExist("Hkey_Current_User\printers\Connections\,," + $PrintServer + "," + $printsetup)
IF $ReturnCode = 1
? $printsetup + " Printer is already installed"
Else
? "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
Endif
$printsetup = ReadLine($handle) ;This part checks if kixtart can open the file and read the contents
LOOP
IF Close($handle)
Beep
? "Error closing file!"
ENDIF
else
? "Unable to open" + $ServerName + "\setup printers\" + $PrintFile
Endif
else
? "Unable to obtain a free system handle."
Endif
EndFunction
|
Top
|
|
|
|
#213703 - 2019-06-13 01:47 PM
Re: printers not showing on first login
[Re: Robdutoit]
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2082
Loc: Tulsa, OK
|
I don't have time today to figure out a way to loop the script...But I did check the IF/ELSE/ENDIFS real quick. They do seem to line up ok. Adding a little more consistent indentation might make it easier to tell.
;================================================================================================
; 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)
WHILE @ERROR = 0
$ReturnCode = KeyExist("Hkey_Current_User\printers\Connections\,," + $PrintServer + "," + $printsetup)
IF $ReturnCode = 1
? $printsetup + " Printer is already installed"
ELSE
? "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
ENDIF
$printsetup = ReadLine($handle) ;This part checks if kixtart can open the file and read the contents
LOOP
IF Close($handle)
Beep
? "Error closing file!"
ENDIF
ELSE
? "Unable to open" + $ServerName + "\setup printers\" + $PrintFile
ENDIF
ELSE
? "Unable to obtain a free system handle."
ENDIF
EndFunction
Edited by ShaneEP (2019-06-13 01:48 PM)
|
Top
|
|
|
|
#213721 - 2019-07-04 06:32 PM
Re: printers not showing on first login
[Re: Robdutoit]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4307
Loc: New Jersey
|
Rob,
I actually defined coding guidelines that the staff need to follow, some of which are:
- 2-space indents for all paired statements (if/endif, loops, etc.) Select/Case is the exception - the "case" is indented one space, and it's commands indented the second space.
- Local var names are $MixedCase, Globals are $CAPS, as are @MACROS. Local vars in functions have a "_" prefix, as in "$_FnVar".
- one blank line between code blocks, 3 blank lines plus a comment divider (; ====) between key logic sections. I use "#" dividers at major divisions, "=" at minor divisions and at the start of each function, and "-" for minor sections.
- Command and Function names are MixedCase
- Spaces between ALL operators
- Use of CRLF at the END of output only. Never start a line with "?". It's a shortcut for CRLF, which traditionally comes at the end of a line. It's often confused with MS BASIC's use of "?" as a shortcut for the PRINT statement, which comes at the start of the line.
You'll find that every UDF that I post will follow these standards.
I use KGEN to generate all scripts, which builds the script from a central UDF library, runs Sanity, tokenizes the script, and even copies the finished script to an alternate (production) location.
All of these standards result in code that's easy for the team to support. We currently have over 100 Kix scripts collectively exceeding 150-thousand lines of code in production on more than 35,000 computers world-wide. Several scripts are in the 12-15 thousand line range.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 179 anonymous users online.
|
|
|