#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: 363
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: 2125
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: 4396
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
|
|
|
|
#213803 - 2020-01-24 05:48 PM
Re: (NA) Re: printers not showing on first login
[Re: NTDOC]
|
syntax53
Fresh Scripter
Registered: 2004-11-17
Posts: 33
Loc: Pennsylvania
|
I was just coming on here to post some similar findings myself. We have been using Kixtart for 20 years now and continue to use it for adding printers, among other things. Over the past few months we have seen an increased number of complaints with printers not showing up. When we run the scripts after they are already logged in the printers always just load right up no problems at all.
Through some debug logging I've find that on some occasions the ADDPRINTERCONNECTION fails with error 87. According to https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499- error 87 is just "The parameter is incorrect" which is not helpful. I have found that if I see that error, wait 5 seconds, and then try again it works fine.
Looking at the logs for a group of machines I did testing on I'd say 50% or more of people logging in get the printers no problem on try #1. The rest get error 87 on the first try and then consistently the second try works fine. I modified my AddPrinterFunction as follows to work around the problem:
FUNCTION AddPrinter_IfNOTExist($_printer, OPTIONAL $_Default)
$AddPrinter_IfNOTExist = 0
$found = 0
$add_printer_attempts = 0
$add_printer_max_retries = 3
$_Default = Val($_Default)
$ret = ReadValue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices", $_printer)
IF @ERROR = 0 $found = 1 ENDIF
IF $found = 0
DO
$add_printer_attempts = $add_printer_attempts + 1
$AddPrinter_IfNOTExist = ADDPRINTERCONNECTION($_printer)
IF $add_printer_attempts < $add_printer_max_retries
;retry on specific errors
IF $AddPrinter_IfNOTExist = 87
SLEEP 5
ELSE
$add_printer_attempts = $add_printer_max_retries + 1
ENDIF
ENDIF
UNTIL $AddPrinter_IfNOTExist = 0 OR $add_printer_attempts >= $add_printer_max_retries
IF $_Default = 1 AND $AddPrinter_IfNOTExist = 0
$ret = SETDEFAULTPRINTER($_printer)
ENDIF
ENDIF
ENDFUNCTION
|
Top
|
|
|
|
#213827 - 2020-02-23 01:50 PM
Re: (NA) Re: printers not showing on first login
[Re: syntax53]
|
Robdutoit
Hey THIS is FUN
Registered: 2012-03-27
Posts: 363
Loc: London, England
|
syntax53. Thank you for your insight on this matter. As a matter of fact this post has the same issue - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=213744&gonew=1#UNREAD
My impression is that the problem is that the Windows 10 first login takes a lot longer than Windows 7 and something has not fully loaded in time for the printer install to take place. Never experienced this problem with Windows 7 and I actually have a new 2019 server installed recently with W7 clients and no issues installing printer on first login. So it's not actually the server side nor the script that is the problem.
In addition to disabling onedrive install (which does increase the login time) and which I have already disabled, it was suggested that one could disable the screen displaying please wait while we setup your computer for your for the first time. Apparently if you disable that, it still shows text, but it improves the initial login time. This may be just enough to improve the login time sufficiently to ensure that printers reliably install on the first login?
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 466 anonymous users online.
|
|
|