Page 1 of 1 1
Topic Options
#206728 - 2013-02-19 10:47 AM Use of shell and prnmngr.vbs to add printers instead of AddPrinterConnection
Curious Offline
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.

 PHP:
$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 Offline
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
#206737 - 2013-02-20 03:45 AM Re: Use of shell and prnmngr.vbs to add printers instead of AddPrinterConnection [Re: Curious]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
where you are getting these errors from?
the program or @error?

and you are running this script as logonscript? via gpo? or via usermanager?

you are not checking that %clientname% is set. it might not be there when script gets the ID...
_________________________
!

download KiXnet

Top
#206740 - 2013-02-20 09:51 AM Re: Use of shell and prnmngr.vbs to add printers instead of AddPrinterConnection [Re: Lonkero]
Curious Offline
Getting the hang of it

Registered: 2004-02-16
Posts: 61
I am getting the error from @ERROR and @SERROR. I see now that my description of the errormessage has not been correct, as I referred to both errors.
The correct will be that @ERROR returns '3012' (or '10') and @SERROR returns 'No Printers were found' (or 'The environment is incorrect')

The script runs from a GPO.
There have been issues about the %ClientName%, but that is solved, and initially in the script I check that the %ClientName% has been set, to ensure that I can process the script further on.

Here's an extraction from my logfile which shows that %ClientName% has been set:

 Code:
18:41:45 ----> Kix versjon: 4.62
18:41:45 ----> @wksta: TS-Server1
18:41:45 ----> %clientname%: User1
18:41:45 ----> Logonserver: \\Logonserver1

18:41:45 ----> DefaultPrinter from registry: \\Printsrv1\Dummy_Printer,winspool,Ne00:
18:41:47 ----> ----------------------------------------------------------------------------------------
18:41:47 ----> Printermappings
18:41:47 ----> Failure adding printer \\Printsrv1\Printer1 3012 No printers were found.
18:41:47 ----> Failure adding printer \\Printsrv1\Printer2 10 The environment is incorrect.
18:41:47 ----> Failure adding printer \\Printsrv1\Printer3 10 The environment is incorrect.
18:41:47 ----> Unsucessful setting \\Printsrv1\Printer1 as default printer: Errorcode 2
18:41:47 ----> ----------------------------------------------------------------------------------------
18:41:48 ----> Default printer at end of login: 
18:41:48 ----> LOGINSCRIPT END


There is NO QUESTION about the printers being available at the time, and what makes this strange is that at my next logon, everything might be ok \:o


Jon
_________________________
I was placed on earth to do a job. Right now I have so much to do, I will never die..

Top
#206743 - 2013-02-20 01:49 PM Re: Use of shell and prnmngr.vbs to add printers instead of AddPrinterConnection [Re: Curious]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
what is the 2 second cap between def from reg and the empty printout line?
removed irrelevant lines?

very nice logging indeed...

one more thing to check, is the spooler service running?
the only reason I could figure out for error 3012, would be stopped/non-responsive spooler subsystem.
_________________________
!

download KiXnet

Top
#206745 - 2013-02-21 08:35 AM Re: Use of shell and prnmngr.vbs to add printers instead of AddPrinterConnection [Re: Lonkero]
Curious Offline
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 \:o

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
#206746 - 2013-02-22 02:52 AM Re: Use of shell and prnmngr.vbs to add printers instead of AddPrinterConnection [Re: Curious]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
the spooler comment is just because of the funky error message. couldn't remember what gives that, so googlified it. when spooler is off, that seems to be error you can get. haven't tested it though. might be worth checking...
_________________________
!

download KiXnet

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 Administrator Offline
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:
 Code:
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:
 Code:
$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! \:D

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 Offline
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
#207479 - 2013-07-22 12:11 AM Re: Use of shell and prnmngr.vbs to add printers instead of AddPrinterConnection [Re: GuruMeditation]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
You might check out this MS article as it seems to apply to your situation...

"No Printers were found" Net work Printer Error -
http://social.technet.microsoft.com/Foru...k-printer-error


If this is a GPO script, we have seen where Mapped Drives and Shared Printers appear to connect properly, but when you look, they are not there. This is because with Vista and above the GPO script does not run in the context of the current user. There are at least two ways around it. One that is easy but is not supported by Microsoft, and I will leave it to you to find if you really want to go that route. The other is to run the part of the script that maps drives and printers in the context of the user. There is a UDF that helps with this, that is based on a vbs/wsf script provided by Microsoft.

RunAsInteractiveUser -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=198514#Post198514

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

You could also have one or two other issues going on... Please see

Windows XP Professional Fast Logon Optimization
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=112428#Post112428

Point and Print Restrictions policy
http://support.microsoft.com/kb/319939

Since the starter of this thread didn't really say what fixed his issue, it would be helpful if you post what solution fixes yours.



Top
#207481 - 2013-07-23 12:24 AM Re: Use of shell and prnmngr.vbs to add printers instead of AddPrinterConnection [Re: Allen]
GuruMeditation Offline
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 Offline
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
#207493 - 2013-07-25 04:50 PM Re: Use of shell and prnmngr.vbs to add printers instead of AddPrinterConnection [Re: GuruMeditation]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Fast Logon and Printer Restrictions are most definitely not limited to XP.
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
0 registered and 989 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.257 seconds in which 0.217 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