#206728 - 2013-02-19 10:47 AM
Use of shell and prnmngr.vbs to add printers instead of AddPrinterConnection
|
Curious
Getting the hang of it
Registered: 2004-02-16
Posts: 61
|
Hey folks.
I have some strange logs for some of my user who's getting their network printers through addprinterconnection.
Sometimes users get their printers, sometimes they don't. I sometimes get errors like '3012 no printers were found' and '10 The environment is incorrect'. The last might have been because I was not running script synchronously, that one is probably sorted out. More precise said: errormessages SOMETIMES get returned like mentioned above, but printers are mapped anyway
We use a wmi-function to list out the users mapped printers. Sometimes it returnes all printers, sometimes some, sometimes only the printer gotten from the terminalserver.
And yes, we are using Citrix XenApp 6 on Win 2008 R2, running a published desktop for users, AND FROM THAT DESKTOP EXECUTING THE PROGRAM IN QUESTION, RUNNING IN A SAFE ZONE AS A PUBLISHED APPLICATION.
We have this poorly written program, which is dependent on having a standardprinter available. Due to errors mentioned above, at startup of the application printers might not always be available, and no default printer set.
I havel also added a dummy-printer that is supposed to get mapped if no standardprinter is set
To debug further on, I'm trying to use the cscript prnmngr.vbs on 2008 servers instead.
What I'm trying to do: Execute a shell statement for each printer I want the user to map, to ensure that the program I use has printers available (and a standardprinter) when it is executed.
For debug purposes I now map printers through a ini-file.
Here's the code i try, but the shell-statement is not right, and that's my main problem right now, can't get this proper.
$ID = left ("%ClientName%", 15)
$PrinterList = Split(ReadProfileString('%logonserver%\NETLOGON\PRINTER\Sikker_Sone.ini', $ID, 'Printer'), ';')
$DefPrinter = ReadProfileString('%logonserver%\NETLOGON\PRINTER\Sikker_Sone.ini', $ID, 'Standard')
debug on
For Each $Printer in $PrinterList
;if AddPrinterConnection($Printer) = 0
$rc = 'c:\windows\system32\cscript.exe c:\windows\system32\printing_admin_scripts\en-us\prnmngr.vbs -ac -p ' + '"\\bksi-fp1\+$printer"'
shell $rc
;shell "c:\windows\system32\printing_admin_scripts\en-us\cscript " + "-ac " + "\\bksi-fp1\" +$printer
$x = WriteLine( 1 , @Time + " ----> " + "Lagt til skriver" + $Printer + @CRLF)
;else
$x = WriteLine( 1 , @Time + " ----> " + "Lykkes ikke å legge til skriver" + $Printer + @error + " " + @serror + @CRLF)
;endif
The syntax for the command is: cscript prnmngr.vbs -ac -p "\\printserver\sharedprinter" The last statement must have double quotes around it.
Any input will be appreciated, and tips for sorting this out - naturally as well 
And one thing more: How does AddPrinterConnection work opposed to what I'm trying here? Maybe it is kind of the same way it works? Anyway... by doing this in a shell, I'm guaranteed that the printer is present when launching tha application.
Cheers - Jon
Edited by Curious (2013-02-19 01:34 PM)
_________________________
I was placed on earth to do a job. Right now I have so much to do, I will never die..
|
|
Top
|
|
|
|
#206730 - 2013-02-19 01:51 PM
Re: Use of shell and prnmngr.vbs to add printers instead of AddPrinterConnection
[Re: Curious]
|
Curious
Getting the hang of it
Registered: 2004-02-16
Posts: 61
|
Well guys, sorted out the syntax myself, so that one's solved.
But would like any input on the way to make the printer-adding bulletproof.
Jon
_________________________
I was placed on earth to do a job. Right now I have so much to do, I will never die..
|
|
Top
|
|
|
|
#206745 - 2013-02-21 08:35 AM
Re: Use of shell and prnmngr.vbs to add printers instead of AddPrinterConnection
[Re: Lonkero]
|
Curious
Getting the hang of it
Registered: 2004-02-16
Posts: 61
|
I had to translate the log into english, cause guess you guys aren't that good in Norwegian as I am So yes, removed irrelevant lines, but left the gap it seems 
Tnx for feedback on the log, it certainly makes it easier to debug strange behaviours, like this one, allthough I just don't get it.
I don't explicitly check the spooler at script exec, but we serve 3-400 users, and one user can be ok, while another has this trouble - at about the same time..
Sequence of ececution has been one of my possible explenations, as several GPO's gets executed at logon. The kix is executed last of the GPO's now.
Maybe sections in the kix gets executed too fast in regard of the network available? But mapping of shares is not a problem, so guess this isn't the issue either.
Just can't get it, and it's bugging me big time.
//Jon
_________________________
I was placed on earth to do a job. Right now I have so much to do, I will never die..
|
|
Top
|
|
|
|
#206753 - 2013-02-22 01:38 PM
Re: Use of shell and prnmngr.vbs to add printers instead of AddPrinterConnection
[Re: Lonkero]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
|
Jon,
Good logging is important and it's nice to see the effort you put into it. You might want to check out the fMsg() UDF, which is specifically designed for message handling and logging.
One of the things that makes most coders avoid logging is that we often need it for debugging and - when used as such - makes us go back into the code to turn it all off. fMsg() can display messages all the time, when debugging is on ($DEBUG=1), or when debugging is at a specific level or below ($DEBUG=3 to display level 1-3 messages). It's also a lot of work to open/write/close, not to mention formatting the messages.
With fMsg(), you can use the following syntax to add multiple levels of logging:fMsg(Msg, LMsg, Nl, Mode, Opt, R, C) All but the first arguments are optional, so fMsg('my message') is displayed on the screen and written with a timestamp to the log.
Usually, the first argument is used for display and logging. The second argument is a different message that's written to the log - sometimes you want a text message on the screen and an error code in the log.
The "Nl" arg is a Boolean that suppresses the CRLF so that you can write a message when an event starts and complete it with status when it ends, all on the same line.
The Mode value controls output and is a binary value. - 1 - suppresses the log timestamp, useful to write multiple events to a line - 2 - adds a timestamp to the screen message - 4 - Displays only when the global var $DEBUG is not zero. This can be used with the OPT value to specify that DEBUG must be greater than some value before displaying the message, allowing many levels of debugging to be placed in your code. - 8 - Performs an "abend" - after displaying/logging the message, it terminates the script execution with the exit code specified by the OPT value. Used when a non-recoverable error is detected. - 16 - Log but do not display on the screen.
I use Mode 20 extensively for debug logging, and use the following during development to see the messages on the screen:$ONSCREEN = 0 ; set to 16 for production - suppress screen messages
$MSG_LOG_= '\path\to\logfile'
$DEBUG = 4 ; very verbose debugging
fMsg('Startup message..)
; some code
fMsg('Log an event...', '', 0, 16) ; suppress on-screen display
; some code
; display a debug message
fMsg('Starting XXX process', '', 0, 4 + $ONSCREEN)
; display a debug message at level 2 or higher
fMsg('FuncName-VarX=' + $VarX', '', 0, 4 + $ONSCREEN, 2) By setting the value of DEBUG via config parameters or command line args, you can control how many messages are logged during debugging, if any. Messages with Debug enabled are prefixed with "-DEBUG-" when writing to the log to distinguish from standard messages.
One comment on your original issue.. a few months back a client that uses our commercial login script complained of printer mapping errors, and each time the error was "The environment is invalid". We provided them with a custom release that offered more debugging detail. We found that, on about 4 of 100+ workstations, that the environment was indeed invalid - it was completely empty! Resetting the user profile had no affect, and the problem affected everyone who logged into the computer. Since this was consistent on specific machines, they wound up re-imaging those systems. It would have been nice to find the actual problem but the effort involved wasn't worth the time spent. The issue occurred only during logon. After the desktop loaded, the script could be run successfully and the environment was correct. You might want to add "SET >env.log" to the start of your login script to see the state of the environment during logon. It was hard to diagnose initially because everything looked correct when the admin logged in and looked at the system.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#207476 - 2013-07-21 05:02 PM
Re: Use of shell and prnmngr.vbs to add printers instead of AddPrinterConnection
[Re: Glenn Barnas]
|
GuruMeditation
Just in Town
Registered: 2013-07-09
Posts: 3
Loc: Germany
|
Hello Forum, I have exactily the same problem mentioned at the top. Users sporadic have the error 3012 or 10 for all printers. After the next logon, no bad Messages apper. It seems that I have the problem only on terminalservers. But I'm still working on that to find a reason. I don't want to use vbscript instead. I used kix because of the easy addprinter function. The other posts did not help me. My script is started with a gpo of a vb script that runs the kix-script with a delay of 20 seconds.
gm
|
|
Top
|
|
|
|
#207481 - 2013-07-23 12:24 AM
Re: Use of shell and prnmngr.vbs to add printers instead of AddPrinterConnection
[Re: Allen]
|
GuruMeditation
Just in Town
Registered: 2013-07-09
Posts: 3
Loc: Germany
|
Hello Allen, thanks for your message. I will check your suggestions soon and will post an update asap. My Script is working very fine. Users (local and Citrix) getting their printers when they are in the regarding AD printer group. But I don't understandy this sporadic problem. Printers will only be removed, when I remove the user from the group. So this issue is a cosmetic problem for me. Since now the is no user who noticed that Problem (it would be affect if the user is expecting a new device at the same time). But I have a remote log what is full of this error messages. However my goal is a clean log and a reliable and stable script.
gm
Edited by GuruMeditation (2013-07-23 12:27 AM)
|
|
Top
|
|
|
|
#207492 - 2013-07-25 04:44 PM
Re: Use of shell and prnmngr.vbs to add printers instead of AddPrinterConnection
[Re: GuruMeditation]
|
GuruMeditation
Just in Town
Registered: 2013-07-09
Posts: 3
Loc: Germany
|
Allen, relly: I can't reproduce the issue on local clients. I only have this on Citrix Terminalservers XenApp 6.5. So I think your links will not help in this case. Because local clients are working (Win7) and the fast logon + PP Restrictions are only for XP.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 989 anonymous users online.
|
|
|