Page 1 of 1 1
Topic Options
#74884 - 2003-05-07 06:33 PM Map printer script error
mig21 Offline
Fresh Scripter

Registered: 2000-07-13
Posts: 21
Loc: Lisbon, Portugal
Hello,

While trying to run this script:

code:
;************Variables ****************
;
$PrinterName = "Xerox DC 2240 - COLOR"
$PRServer = PTLPPD01
$PRShare = "XEROX COLOR"
$PrtGroup = MIS
;
;***************************************
;
Break on
DIM $x
IF @INWIN=1
IF INGROUP("\\@WKSTA\Power Users") OR INGROUP("\\@WKSTA\Administrators")
mapprinter($PRServer,$PrinterName)
ELSE
$x=MessageBox("The Network logon process has attempted to update your printers to the new print servers, however, it appears that you may not have sufficient rights to add a printer at this time. Please contact the Helpdesk for further assistance.", "Add Printer Warning!", 16)
ENDIF
ENDIF

;******************************************************************
; as seen on USF section http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000153
;This Function maps or deletes NetworkPrinter by Groupmemberships
; if the user is member of the group, he will get mapped the networkprinter
; if the user is NOT a member of the group, he don't get the networkprinter or
; the printer is deleted on his PC
;
;Start with mapprinter(, ,,)
;
;This Function is tested on a NT4 Domain with NT4 and W2k Clients only!
;******************************************************************
function MapPrinter($PRServer, $PRShare, $PrinterName, $PrtGroup)
$regkey="HKCU\Printers\Connections\,,"+$PRServer+","+$PrinterName
if ingroup($PrtGroup) =1
if keyexist($regkey)
? "Drucker \\$PRServer\$PRShare bereits vorhanden"
return
else
if addprinterconnection("\\"+$PRServer+"\"+$PRShare) =0
? "Attach Network-Printer \\$PRServer\$PRShare"
else
? "Error by connecting to \\$PRServer\$PRShare"
? @serror
endif
endif
else
if keyexist($regkey)
if delprinterconnection("\\"+$PRServer+"\"+$PRShare) =0
?" Delete NetworkPrinter \\$PRServer\$PRShare"
else
?" Error by deleting \\$PRServer\$PRShare"
? @Serror
endif
else
return
endif
endif
;
endfunction

All I cat get on console windows is:
"Script error : expected ENDFUNCTION !
endfunction"

If I try to debug, again I get the same error.
I'am running W2kPro on NT4 DC.

Thx,
mig21

[ 07. May 2003, 20:17: Message edited by: mig21 ]

Top
#74885 - 2003-05-07 06:35 PM Re: Map printer script error
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, you have additional quote:
$PrinterName"

remove it and that error is removed too [Wink]

then, this UDF seems to want to give all the parameters, otherwise it will error out too.
_________________________
!

download KiXnet

Top
#74886 - 2003-05-07 06:37 PM Re: Map printer script error
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
additionally, you probably should read how to use UDFs from the FAQ forum.

also check addprinterconnection() from kixtart manual as it fits to your script just fine.

then, one does not need to be admin to add a printer for himself.
_________________________
!

download KiXnet

Top
#74887 - 2003-05-07 06:38 PM Re: Map printer script error
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Definitely not a very clean UDF, no error checking, no header, and prints stuff to the console.
_________________________
There are two types of vessels, submarines and targets.

Top
#74888 - 2003-05-07 07:25 PM Re: Map printer script error
mig21 Offline
Fresh Scripter

Registered: 2000-07-13
Posts: 21
Loc: Lisbon, Portugal
Lonkero & SeaLeopard,

Thanks for your thoughts.
I corrected the additional quote at $PrinterName"
and now I'll try do discover what this means:

Script error : invalid method/function call: missing required parameter 3 !
mapprinter($PRServer,$PrinterName)

Unfortunatelly no more info on UDF topic MapPrinter from MasterOfDesaster.

Thx again for your time.
mig21

Top
#74889 - 2003-05-07 07:31 PM Re: Map printer script error
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
As you've already been told, all four parameters are REQUIRED. That's what the error message is about.
_________________________
There are two types of vessels, submarines and targets.

Top
#74890 - 2003-05-07 07:34 PM Re: Map printer script error
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
If you read the function you will see that it requires 4 parameters.

quote:
;$PRServer = Printserver
;$PRShare = Sharename of the Printer
;$Printername = The real Name of the Printer (not of the PrinterDriver!)
;$PrtGroup = The Group in the Domain where the user must belong to, to get the printer

none of which are listed as optional.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#74891 - 2003-05-07 08:21 PM Re: Map printer script error
mig21 Offline
Fresh Scripter

Registered: 2000-07-13
Posts: 21
Loc: Lisbon, Portugal
Howard,

I dont't get it... I've declared the 4 parameters.
What can the script be expecting?

mig21

Top
#74892 - 2003-05-07 08:25 PM Re: Map printer script error
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
However, you only provide two parameters into the function. See your own code
code:
mapprinter($PRServer,$PrinterName)

. The last two REQUIRED parameters are NOT provided, though you've declared varables for them.
_________________________
There are two types of vessels, submarines and targets.

Top
#74893 - 2003-05-07 08:26 PM Re: Map printer script error
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
This was the function call you previously posted.
code:
mapprinter($PRServer,$PrinterName)

This shows 2 parameters. What is your current code?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#74894 - 2003-05-07 09:07 PM Re: Map printer script error
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
and like I said before, you should really look into faq forum topic:
How to use UDFs

just like I said in the first reply, your call is wrong.

and like I said in the second reply, you are better out with inbuild function:
AddPrinterConnection( ) Add a connection to a network printer (NT family only)

but your ingroup conditions are not needed at all.

so your full script you posted can be replaced with simple:
code:
$returncode=addprinterconnection("\\PTLPPD01\XEROX COLOR")

_________________________
!

download KiXnet

Top
#74895 - 2003-05-07 09:19 PM Re: Map printer script error
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
And you also need to surround strings with quotes if you try to assign a string to a variable.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


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

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.069 seconds in which 0.03 seconds were spent on a total of 12 queries. Zlib compression enabled.

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