Page 1 of 1 1
Topic Options
#212894 - 2017-11-17 09:42 PM AddPrinterConnection Inconsistent Errorcode:10
Sjaak Offline
Just in Town

Registered: 2017-11-17
Posts: 2
Loc: Florida
Hi All,

I'm running in to an issue where a small group of our users get "Errorcode: 10 : The environment is incorrect" when mapping printers through our printer mapping script.

We run VMWare and most of the users are on one pool so they basically all have the same configuration and still printer mapping will fail for some.

We run Kix 4.66 on Windows 7.
Our printer mapping script uses an array to define individual printers and an array to define default printers. In addition to setting the individual printers, users get printers mapped based on group membership.
Below is a code snippet for the individual printer mapping:

 Code:
; Individual printer mapping -------------------------------------------------------------------------------------
For Each $row In $IPrinters
  for each $element in $row
	if @USERID = $element
;		"Map " + $row[0] + " FOR " + @USERID ?
		$MyPrinter=$row[0]
		addprinterconnection ($MyPrinter)
			If AddPrinterConnection ($MyPrinter) = 0
;				"Added printer connection to $MyPrinter...." ?
				If RedirectOutput($LogFile) = 0 ;log success to log file
					"@DATE,@TIME,@MSECS,@USERID,Mapped printer $MyPrinter" ?
				EndIf
				RedirectOutput("") ;Redirect output back to screen
			Else
				$errorcode=@Error ;store error code
				$errordes=@SERROR ;store error description
;				"Printer connection to $MyPrinter failed!" ?;show failed
;				"Error code: " + @ERROR + " : " + @SERROR ?;show error code and description
				If RedirectOutput($LogFile) = 0 ;log failure to log file
					"@DATE,@TIME,@MSECS,@USERID,Printer connection to $MyPrinter failed!" ?
					"@DATE,@TIME,@MSECS,@USERID,Errorcode: $errorcode : $errordes" ?
				EndIf
				RedirectOutput("") ; Redirect output back to screen
			EndIf
	endif
  Next
Next


To add to the confusion, we will see Errorcode: 10 in the log for some users but they can still print.

Thanks for any advise,

Sjaak

Top
#212895 - 2017-11-17 10:00 PM Re: AddPrinterConnection Inconsistent Errorcode:10 [Re: Sjaak]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4560
Loc: USA
I haven't seen that error message since the early days of vista, when there truly was a problem using network printers.

Not that any of these suggestions will fix your problem but things to consider...

If the printer is already connected, there really is no reason to reconnect it every time the user runs the script. One option is to use the PrinterConnection udf and check for the printer before adding it. PrinterConnection can do other useful things as well. You can also use Primapstate udf to check for network printers.

Curious what your $IPPrinters variable contains.

Some of your lines of code would benefit by putting $RC= in front of the functions so that it silences all those 0s and 1s from displaying during the execution of the script. For example... $RC=addprinterconnection(...) and $RC=redirectoutput(...)

PrinterConnection -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=203840#Post203840

How to use UDFs -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=81943#Post81943

The rest of the UDFs are here -
http://www.kixtart.org/forums/ubbthreads.php?ubb=postlist&Board=7&page=1

Top
#212896 - 2017-11-17 10:24 PM Re: AddPrinterConnection Inconsistent Errorcode:10 [Re: Allen]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
I'm guessing the $row consists of a Printer name, followed by all users that get that printer. I would suggest using the AScan function to see if the user is in that row, instead of looping through each element needlessly.
Top
#212899 - 2017-11-17 10:44 PM Re: AddPrinterConnection Inconsistent Errorcode:10 [Re: ShaneEP]
Sjaak Offline
Just in Town

Registered: 2017-11-17
Posts: 2
Loc: Florida
Thanks Allen and Shane for the quick reply.

Even if the suggestions will not directly fix my issues I appreciate the input.

I will do some reading this weekend about the PrinterConnection udf

Also the $RC suggestion will help to cleanup the code thanks.

Additionally I will look in to the AScan function.

All great suggestions, Thanks.

BTW:
$IPrinters is an array with individual printermappings:
 Code:
; Individual printer mapping Array -------------------------------------------------------------------------------
; Use only for individual printers or small groups
Dim $IPrinters[62]

$IPrinters[0]="" ; place holder
$IPrinters[1]="$EE102A_Printer","user1"
$IPrinters[2]="$EE102C_Printer","user2"
$IPrinters[3]="$EE102L_Copier"
$IPrinters[4]="$EE102Front_Printer","user3","user4","user5"
....
....

Top
#212901 - 2017-11-18 02:46 PM Re: AddPrinterConnection Inconsistent Errorcode:10 [Re: Sjaak]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Interesting concept for resource mapping, but I'll tell you it won't scale well, especially if you're defining the array in your script.

Here's a couple of ideas:

The example below extracts the printer ID immediately, then converts the array to a temporary delimited string ("~printer~user~user2~"). Then a simple InStr() function is used to check for the USERID being present in the temp string. By wrapping the USERID in the same delimiters, you can avoid situations where a partial match might occur ("Jon" matches "Jon" and "Jonathan").

 Code:
Break On

Dim $IPrinters[1]

$USERID = 'Barney'   ; simulate content of @USERID

; Printer mappings - printer followed by list of users - only 1 for test
$IPrinters[0] = 'Prnt05', 'Fred', 'Barney', 'Wilma', 'Betty'
$IPrinters[1] = 'Prnt06', 'George', 'Jane', 'Elroy', 'Judy'

; Enumerate the mapping table
For Each $Row in $IPrinters
  ; Get the printer from element 0
  $MyPrinter = $Row[0]
  ; convert to temp string with "~" delimiters, including start and end of string
  $Tmp = '~' + Join($Row, '~') + '~'
  ' Is a delimited version of the user ID found in the temp string? 
  If InStr($Tmp, '~' + $USERID + '~')
    'Map printer ' $MyPrinter ' for ' $USERID ?
  EndIf
Next


A much more sustainable method would be to user an INI file, something like this:
 Code:
[PRINTERS]
;List printers - the value is unimportant, as it simply allows defining a list to enumerate
Prnt01=1
Prnt02=1
Prnt03=1

; list the parameters related to each printer
; UNC is the unc path, which allows simpler names for administration
; Users is a comma-delimited list of individual user accounts used to map the printer
; Groups is a comma-delimited list of AD Groups used to map the printer
[PRNT01]
UNC=\\server\printer
Users=User1,User2,User3

[PRNT02]
UNC=\\server\printer
Users=User1,User3,User5
Groups=PR-Prnt02

[PRNT03]
UNC=\\server\printer
Users=User2,User4,User6
and here's some logic to manage this:
 Code:
Break On

$USERID = 'User3'

; Get the list of printers to be mapped
$aPrinters = Split(ReadProfileString('.\Prnt.ini', 'PRINTERS', ''), Chr(10))

; Enumerate the list of printers and check for user or group-based mapping
; Set MapIt flag if either match is found
For Each $Printer in $aPrinters

  If $Printer  ; a non-blank value? 
    $MapIt = 0  ; don't map, by default

    'DEBUG: processing ' $Printer ?	; debugging

    ; Tmp contains comma-delimited list of users, including delims at start/end of string
    $Tmp = ',' + ReadProfileString('.\Prnt.ini', $Printer, 'Users') + ','

    ; if we match the current user id, map the printer. Note the delimiter is now ","!
    If InStr($Tmp, ',' + $USERID + ',')
      $MapIt = 1  ; Ok to map this printer
    EndIf

    ; Check for AD Group based mapping
    $Tmp = ReadProfileString('.\Prnt.ini', $Printer, 'Groups')
    If InGroup($Tmp, $USERID)
      $MapIt = 1
    EndIf

    ; If MapIt is true, perform the printer mapping and log / display the action
    If $MapIt
      $PrtUnc = ReadProfileString('.\Prnt.ini', $Printer, 'UNC')
      'Maping printer ' $Printer ' (' $PrtUnc ') for ' $USERID ?
      ; the printer mapping logic goes here...
      ; AddPrinterConnection($PrtUnc)
      ; @SERROR ?  ; show result
      ; add error-handling logic...
    EndIf

  EndIf
Next
This will be much more flexible, eliminate issues from needing to change the code every time a mapping changes.

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

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 1005 anonymous users online.
Newest Members
min_seow, Audio, Hoschi, Comet, rrosell
17881 Registered Users

Generated in 0.131 seconds in which 0.102 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