Page 1 of 2 12>
Topic Options
#187762 - 2008-05-20 09:59 PM Assigning printers in Presentation Server 4.5
RB_Trout Offline
Fresh Scripter

Registered: 2008-05-20
Posts: 13
Loc: USA
I've got a very basic KiXtart script called from the login1.bat file for all users. The basic parameters are if member of group "A", then assign these printers with ADDPRINTERCONNECTION (\\server\printersharename). I've tried with " inside the paranthesis and without, no luck either way.
As administrator and running debug, I can step through the script, yet no printers are added. I'm stumped.
PS - I'm hoping I can get this to work, instead of logging in as each user and assigning the printers manually.


Edited by RB_Trout (2008-05-20 10:02 PM)

Top
#187767 - 2008-05-20 11:16 PM Re: Assigning printers in Presentation Server 4.5 [Re: RB_Trout]
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
 Code:
if ingroup ('group name')
$rc=addprinterconnection('\\server\sharename')
endif


You might want to use primapstate.udf to first check to see if it is already mapped. You can also elect to set whether it is a default printer or an additional printer.

Top
#187772 - 2008-05-21 12:29 AM Re: Assigning printers in Presentation Server 4.5 [Re: tjcarst]
RB_Trout Offline
Fresh Scripter

Registered: 2008-05-20
Posts: 13
Loc: USA
No luck on that, either.
Top
#187774 - 2008-05-21 04:53 AM Re: Assigning printers in Presentation Server 4.5 [Re: RB_Trout]
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
Are you using the \\server\share and not \\server\local printer name?

Use the path you would use when adding the printer from Start, Run \\server\share. Post the code you are using here, maybe there's a syntax error.

Also, are the groups user groups (ingroup) or comptuer groups (computeringroup). I map printers based upon computers not users and there is a difference.

Top
#187783 - 2008-05-21 10:02 AM Re: Assigning printers in Presentation Server 4.5 [Re: RB_Trout]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
The most important bit if information that you need is the reason *why* the printer is not being added.

You can find this information in two places. Firstly, if the printer mapping is failing then there will almost certainly be entries in the event logs - check both System and Application logs.

Secondly, the command itself will tell you why the mapping failed. It's not always the complete answer, but it will often give you a clue.

Try something like this:
 Code:
If InGroup('group name')
	If AddPrinterConnection('\\server\sharename')
		"ERROR: Failed to add printer, reason: ["+@ERROR+"] @SERROR"+@CRLF
	Else
		"Printer added successfully"+@CRLF
	EndIf
EndIf


This will tell you a couple of things.
  • If the printer is added OK you will get a message confirming it.
  • If the printer add fails you will get a message telling you what the error code was. It might be a bit obtuse, for example "[5] Access denied" can be caused by a lot of different problems, but at least it will give you a clue where to look next.
  • It is possible that you will get no message - in this case you know that the problem is in the InGroup()


Don't forget to check the event logs though - the messages in there are usually more informative.

Top
#187801 - 2008-05-21 04:37 PM Re: Assigning printers in Presentation Server 4.5 [Re: Richard H.]
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
Maybe it is permissions on the printer? Can you add the printer logged in as a regular user? Does Start, Run \\server\printershare work? If so, Richard is correct in that it may be your ingroup? If not, permissions?
Top
#187805 - 2008-05-21 08:09 PM Re: Assigning printers in Presentation Server 4.5 [Re: tjcarst]
RB_Trout Offline
Fresh Scripter

Registered: 2008-05-20
Posts: 13
Loc: USA
 Code:
if ingroup('ITtest')
  if  ADDPRINTERCONNECTION ('\\PRINT01\HB_LSC_4250')
   "ERROR: Failed to add printer, reason: ["+@ERROR+"] @SERROR"+@CRLF
	Else
		"Printer added successfully"+@CRLF
	EndIf
   ADDPRINTERCONNECTION ('\\PRINT01\HB_LSC_HP')
   ADDPRINTERCONNECTION ('\\PRINT01\MIS_1022')
   ADDPRINTERCONNECTION (\\PRINT01\OR_LSC_HP)
   setdefaultprinter (\\PRINT01\MIS_1022) 
   ?"  ITTest'S Printers assigned"
endif


Sample of the code. I logged in as my test user and added the above listed printer without a hitch. Logged out and back in, the printer was still there. Not a permissions issue. The above script showed no errors. The event log on the test server showed only 1 error about not creating an client printer due to drivers.


Edited by Allen (2008-05-21 10:19 PM)
Edit Reason: added code tags

Top
#187808 - 2008-05-21 10:13 PM Re: Assigning printers in Presentation Server 4.5 [Re: RB_Trout]
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
There should be a ' around the \\sserver\share name inside the (). I don't usually have a space before the ( but not sure that matters.

To see the error on the screen, precede the text with ?

You're missing an endif. You have two If and will need matching endif. You should be getting a beep and error when running your code.

When posting code, put the word CODE surrounded by square brackets before it and /CODE with square brackets after it:
 Code:
if ingroup('ITtest')
   if ADDPRINTERCONNECTION('\\PRINT01\HB_LSC_4250')
   ? "ERROR: Failed to add printer, reason: ["+@ERROR+"] @SERROR"+@CRLF
   Else
   ? "Printer added successfully"+@CRLF
   Endif  
EndIf

ADDPRINTERCONNECTION('\\PRINT01\HB_LSC_HP')
ADDPRINTERCONNECTION('\\PRINT01\MIS_1022')
ADDPRINTERCONNECTION('\\PRINT01\OR_LSC_HP
setdefaultprinter('\\PRINT01\MIS_1022') 


Edited by tjcarst (2008-05-21 10:20 PM)

Top
#187809 - 2008-05-21 10:31 PM Re: Assigning printers in Presentation Server 4.5 [Re: tjcarst]
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
I swapped your group, print server, and share names for my own and can run the code I posted and successfully map printers.

So, your server has the drivers and you can map to the \\server\share when you are logged into the same workstation when logged in as the user, using Start, Run, but when you run the script from the command line as the user, you get an error about drivers?

Top
#187810 - 2008-05-21 10:32 PM Re: Assigning printers in Presentation Server 4.5 [Re: tjcarst]
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
Remove the space after addprinterconnection? Shouldn't matter. Hmmm.
Top
#187813 - 2008-05-21 11:01 PM Re: Assigning printers in Presentation Server 4.5 [Re: tjcarst]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
The space won't matter..

A somewhat unrelated comment:
 Code:
   ? "ERROR: Failed to add printer, reason: ["+@ERROR+"] @SERROR"+@CRLF

while this kind of logging is good to do, this syntax tends to be complicated/crowded. This often leads to other problems...

If you are not defining NoMacrosInStrings, and this message is here simply to troubleshoot, you can greatly simplify the format to
 Code:
   "ERROR: Failed to add printer, reason: [@ERROR] @SERROR" ?

If this is a permanent logging message and you want to follow good practice, you can still simplify it a bit. The "?" is not a print command, it's a shortcut for @CRLF, so you've effectively got a newline command at the beginning and end of that output line. Probably not what you want, and certainly not consistent. The "?", like @CRLF (or pressing ENTER, for that matter) usually comes at the end of a line, not the beginning. The "+" is not required for simple output - replacing them with spaces makes things a bit less jumbled. "+" concatenates a string, which would be appropriate for something like $X = "this " + "and that". Note, too, the rearranged quotes. This was a typo in Richard's original post.
 Code:
   "ERROR: Failed to add printer, reason: [" @ERROR "] " @SERROR ?

None of this will directly fix your print map issue, but not paying attention to the little things will often lead to extra or misplaced quotes, which can have a profound effect on the code that follows. Having clean, well formatted code, and following simple "best practice" rules will go a long way helping to troubleshoot your scripts.

In fact, this kind of output is so important that I have a suite of UDFs to handle it. You can get the MSG() UDF from my web site, which has the following UDFs (and more):
MSG(text,flag) - outputs TEXT, suppress CRLF if flag is true
Abend(text,error) - outputs TEXT, exits script with ERROR
Dbg(text) - outputs TEXT only if Global var DEBUG is true

I'd wager that most seasoned coders have a similar collection.

Glenn

PS - PostPrep (or PPCL, from the top of the Advanced forum) to color-code your script, and Sanity to check basic syntax will go a long way in troubleshooting, too. The Sanity UDF posted here is missing the last 5-6 lines - grab the complete version from my web site.
_________________________
Actually I am a Rocket Scientist! \:D

Top
#187814 - 2008-05-21 11:40 PM Re: Assigning printers in Presentation Server 4.5 [Re: Glenn Barnas]
RB_Trout Offline
Fresh Scripter

Registered: 2008-05-20
Posts: 13
Loc: USA
I guess I'm missing something. I tried these lines of script. Do I need these functions somewhere on my system? If so, how do I download?
Top
#187815 - 2008-05-21 11:45 PM Re: Assigning printers in Presentation Server 4.5 [Re: RB_Trout]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
If you're referring to the Msg(), Dbg(), and Abend() UDFs I referenced...

"You can get the MSG() UDF from my web site"

might be what you missed. The MSG() udf is published on the Resources page, and contains those and other UDFs in a single posting. URL is in my sig.

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

Top
#187821 - 2008-05-22 11:56 PM Re: Assigning printers in Presentation Server 4.5 [Re: Glenn Barnas]
RB_Trout Offline
Fresh Scripter

Registered: 2008-05-20
Posts: 13
Loc: USA
I've discovered that it has to do with my ingroup for whatever reason. I removed the if ingroup and made the above code it's own .kix file and called it directly from the DOS prompt. I got the printers assigned, but it returned error code 2 on setting the default printer. Now I need to see what's up with my ingroup statement and then figure out the default printer.
Top
#187822 - 2008-05-23 12:01 AM Re: Assigning printers in Presentation Server 4.5 [Re: RB_Trout]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Error 2 is "not found" - check that you're specifying the right name.

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

Top
#187823 - 2008-05-23 12:03 AM Re: Assigning printers in Presentation Server 4.5 [Re: Glenn Barnas]
RB_Trout Offline
Fresh Scripter

Registered: 2008-05-20
Posts: 13
Loc: USA
It's one of the ones just assigned, same spelling, etc.
Top
#187824 - 2008-05-23 12:37 AM Re: Assigning printers in Presentation Server 4.5 [Re: RB_Trout]
RB_Trout Offline
Fresh Scripter

Registered: 2008-05-20
Posts: 13
Loc: USA
I created that printer on another server and shared it. Then told .kix to add it and set it as default, it worked no problems. I don't understand why, but I can live with it.
The only thing left is the ingroup statement. Inside the parenthesis, I've tried no quotes, single quotes & double quotes, no luck at all.

Top
#187825 - 2008-05-23 01:07 AM Re: Assigning printers in Presentation Server 4.5 [Re: RB_Trout]
RB_Trout Offline
Fresh Scripter

Registered: 2008-05-20
Posts: 13
Loc: USA
 Code:
if ingroup("DMLSC")
  ADDPRINTERCONNECTION (\\print01\DM_LSC_4250)
  ADDPRINTERCONNECTION (\\print01\DM_LSC_HP)
  SETDEFAULTPRINTER (\\print01\DM_LSC_4250) 
  ?"  DM LSC Printers assigned"
endif


Doesn't work no matter how I've tried it. If I remove the if ingroup/endif, it works perfectly.


Edited by RB_Trout (2008-05-23 01:08 AM)

Top
#187826 - 2008-05-23 01:25 AM Re: Assigning printers in Presentation Server 4.5 [Re: RB_Trout]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Have you tried flushing the group token cache?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#187827 - 2008-05-23 01:46 AM Re: Assigning printers in Presentation Server 4.5 [Re: Les]
RB_Trout Offline
Fresh Scripter

Registered: 2008-05-20
Posts: 13
Loc: USA
I have no idea what that is.
Top
Page 1 of 2 12>


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

Who's Online
0 registered and 132 anonymous users online.
Newest Members
MaikSimon, kvn317, kixtarts2025, SERoyalty, mytar
17872 Registered Users

Generated in 0.079 seconds in which 0.024 seconds were spent on a total of 15 queries. Zlib compression enabled.

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