Page 1 of 1 1
Topic Options
#213679 - 2019-05-15 09:32 PM printers not showing on first login
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
Running Windows 10. Logon script mostly runs perfectly on first login and I can see that all the settings are being applied even @domain coding, but half the time the printers are not installed on first login, so user has to logout and log back in again.

Is there anything to either shorten the Windows 10 Setting up Profile time (as its way longer than Windows 7) or how can I tell the script to wait for whatever to load before installing the printers as I presume that something is not loaded in time on the first loging.

I have made the printers the very last item to run and am using the addprinterconnection command.

I will also see if I can't investigate shortening the Windows Profile Creation time as its significantly longer than Windows 7 Creation time.

Top
#213680 - 2019-05-16 01:25 AM Re: printers not showing on first login [Re: Robdutoit]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Are you logging the results or displaying the error codes to the screen to see what is happening? And/Or do you see the logon script cmd box appear during this profile creation that you mention?

Are you running a Startup Script or Logon Script?

When the printers fail to install, do the mapped drives fail as well?


I can't say I have seen this though. I do have Wait for Network policy, Run logon scripts synchronously policy and use a traditional Logon Script for Mapping Drives and adding Printers.


Top
#213681 - 2019-05-16 01:40 AM Re: printers not showing on first login [Re: Allen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Just happened to do a search and found another thread you started very similar to this one.

http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=206481#Post206481

If you haven't made these GPO changes yet, I think it's pretty solid bet, the answer is now in both threads.

Top
#213682 - 2019-05-16 07:06 PM Re: printers not showing on first login [Re: Allen]
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
Hi Allen,

I have Computer GPO defined that enables "Always wait for the network at computer startup and logon" and the issue is not the @domain issue because I am using the @domain setting to apply other settings because we are now using DFS. Everything else in the script is working perfectly except for the printers on first login. The script is definitely running. This is the logon script I am talking about not the startup script. Printers are assigned by logon script, not startup script although perhaps I should review that policy.

We are not using mapped drives anymore. Just windows libraries redirected to DFS Links. These are being setup on first login no problem.

How do you log the results? That would help to identify what the cause is. I can't use the screen because if I run the script manually it will work as the windows profile will have by that time loaded.

I have not seen the problem before myself. Printers have always installed on first login. If I can log the results that would help identify the cause.

Top
#213683 - 2019-05-17 03:25 AM Re: printers not showing on first login [Re: Robdutoit]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Rob,

My Universal Login Script is still available, and can be downloaded from http://www.mspbuilder.com. Still free for 1-2 domain controllers. Logging is, well, intense - that might shed some light on the problem.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#213684 - 2019-05-18 01:25 PM Re: printers not showing on first login [Re: Glenn Barnas]
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
I think that what I will do first is compare my Windows 7 script with my windows 10 script and see what is different. The W10 script was based on W7 script, I just edited out W7 specific things and added W10 and 64 bit specific things. However, I may have remmed out something that was in W7 because I never had this issue with printers not installing before.

Having said that, I think the issue is because the W7 new login is much faster than the W10 login and I don't think the W10 system is completely loaded by the time the script gets to the printer install section. I think that something needs to be loaded in the profile before you can install the printers.

Perhaps all I need to do is remove the active setup in W10 as this improved the W7 login speed, but I thought that this was not relevant for W10. But other articles indicate that it is still relevant. That could shave off ten seconds for a new login.

Top
#213685 - 2019-05-18 01:31 PM Re: printers not showing on first login [Re: Robdutoit]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Wait - You have O/S specific login scripts???
_________________________
Actually I am a Rocket Scientist! \:D

Top
#213686 - 2019-05-18 04:13 PM Re: printers not showing on first login [Re: Glenn Barnas]
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
In a general way no. It's more that the W7 script was written from the ground up in 2012 and obviously edited over the years. So it was over 5 years old and I wanted to get rid of some legacy coding from the original script. I was also moving away from drives mapped to a server and using Windows Libraries mapped to DFS.

I upgraded a client from Windows Server 2008 32 bit and Windows 7 32 bit to Windows Server 2016 64 bit and Windows 10 64 bit. I took the W7 script that I had designed in 2012 and updated over the years and applied it to the new system.

However, I had to make a lot of changes for 64 bit clients and because W10 also prevented quite a lot of registry entries. In addition, I removed W7 specific settings that were not relevant in W10. Also the new netowrk design is very different from the ones that I setup in 2012.

I am upgrading all my other clients to Server 2019 and W10 this year. So they are running on the old script. I saw no value in changing their scripts to run the new OS as they don't have W10 yet and I don't want the new script to have legacy W7 or 32 bit coding as well as legacy network configs.

So in a general way I don't have OS specific scripts. But the new system is very different - GDPR Compliant, 64 bit, DFS, Windows Libraries Drives and many other changes like that. So a lot of legacy coding was removed.

Top
#213699 - 2019-06-12 10:32 AM Re: printers not showing on first login [Re: Robdutoit]
Robdutoit Offline
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:

 Code:

;================================================================================================
;  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 Moderator Offline
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.

 Code:
;================================================================================================
;  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
#213704 - 2019-06-14 11:03 AM Re: printers not showing on first login [Re: ShaneEP]
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
@shaneEP. That is a brilliant idea. Don't know why I didn't think of that before! Probably because I don't do coding for a living! I think that I will do this for my entire script - mainly the UDF's File as it would make it far easier to read the code as you rightly pointed out. I can now clearly see that the if else endifs are lining up. Thanks.
Top
#213705 - 2019-06-14 12:40 PM Re: printers not showing on first login [Re: Robdutoit]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
There's a Sanity() UDF that helps with this kind of checking - just write a simple script to ask for the name of the file to check, pass that name to Sanity() and it will perform the following checks:
* Generate list of Declared VarNames - Global, Main, & per UDF
* Identify VarNames declared by both DIM and GLOBAL
* Identify VarNames that were not declared
* Identify VarNamed Declared but not used
* Identify suspected use of Vars or Macros in strings
* Identify suspected mismatched single & double quotes
* Identify suspected mismatched parens
* Identify suspected mismatched If/EndIf statements
* Identify suspected mismatched While/Loop statements
* Identify suspected mismatched Do/Until statements
* Identify suspected mismatched For/Next statements
* Identify suspected mismatched Select/EndSelect statements

It creates three files:
VarInfo.ini listing of vars by function
Warnings.csv CSV format listing of generated warnings
codemap.txt A Map of the structure of the script w/ warnings about unbalanced If, While, Do, For, and Select statements
_________________________
Actually I am a Rocket Scientist! \:D

Top
#213707 - 2019-06-16 10:39 AM Re: printers not showing on first login [Re: Glenn Barnas]
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
Thanks Glenn. I don't think that there is anything wrong with my scripts as most of the coding has been operational for years. But it will be well worth running the Sanity Udf to see what comes to light. I think that the main thing that I need to do with my UDF's is to write it as ShaneP suggested. The difference in reading comprehension is incredible - it is so much easier to follow which if goes with which end statement.

I will get on with this next week as I won't have time this week to do it.

Top
#213720 - 2019-07-03 10:33 AM Re: printers not showing on first login [Re: Robdutoit]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
How did things work out for you Rob?

I haven't used it in a while but Glenn has some great scripts, including that Sanity checking tool.

Top
#213721 - 2019-07-04 06:32 PM Re: printers not showing on first login [Re: Robdutoit]
Glenn Barnas Administrator Offline
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! \:D

Top
#213722 - 2019-07-07 10:24 PM Re: printers not showing on first login [Re: Glenn Barnas]
Robdutoit Offline
Hey THIS is FUN
***

Registered: 2012-03-27
Posts: 363
Loc: London, England
Sadly I have not had time to do this as yet. Both tidying up the script like shane has shown, nor had time to sort the out the printer issue. Too many other things demanding my time and attention.

As they say - it's on my list! I am installing a new network for one of my clients in a couple of weeks. So I will see if I can get this done at the same time as it would be the perfect time to organise it.

Top
#213723 - 2019-07-07 10:39 PM (NA) Re: printers not showing on first login [Re: Robdutoit]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Good luck and let us know how things turn out.
Top
#213803 - 2020-01-24 05:48 PM Re: (NA) Re: printers not showing on first login [Re: NTDOC]
syntax53 Offline
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:

 Code:
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 Offline
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
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.072 seconds in which 0.025 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org