Page 2 of 2 <12
Topic Options
#74068 - 2003-03-17 06:02 AM Re: Mapping Printers by IP Subnet
Adam Crichton Offline
Fresh Scripter

Registered: 2003-03-17
Posts: 15
Loc: Canada
OK looking good - nearly there I'm sure. No errors from the scripts, but also no printers on the client.

Checked Printer and Queue names are the same in this case, so that can't be it.

Why isn't anything ever easy . . .

Thanks.

Top
#74069 - 2003-03-17 06:06 AM Re: Mapping Printers by IP Subnet
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22344
Loc: OK
one minor.
you must use printer's sharename when doing addprinterconnection() and printername when doing setdefaultprinter.

and these names look not like sharenames [Wink]
_________________________
!

download KiXnet

Top
#74070 - 2003-03-17 06:07 AM Re: Mapping Printers by IP Subnet
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
You will have to add code to verify you are getting into the proper case statement. You should also evaluate the return code from the AddPrinterConnection function.

code:
AddPrinterConnection( )

Action: Adds a connection to the specified printer for the current user.

Syntax: ADDPRINTERCONNECTION ("printer name")

Parameters: Printer name

The (share)name of the printer to which to connect.

Remarks: This function is available only on Windows NT family,
and can be used only to connect to printers on a server running the
Windows NT/2000/XP operating system.

When Windows NT connects to the printer, it may copy printer driver
files to the local computer. If the user does not have permission to copy
files to the appropriate location, ADDPRINTERCONNECTION fails, and
@ERROR returns ERROR_ACCESS_DENIED.


Returns: 0 Printer connection established
Error code Function failed


See Also: DelPrinterConnection( ), SetDefaultPrinter( )

Example: If ADDPRINTERCONNECTION ("\\vleerbeer\hp laserjet 4") = 0
? "Added printer connection...."
else
? "@error @serror"
Endif




[ 17. March 2003, 06:08: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#74071 - 2003-03-17 06:18 AM Re: Mapping Printers by IP Subnet
Adam Crichton Offline
Fresh Scripter

Registered: 2003-03-17
Posts: 15
Loc: Canada
Printername and Sharename in this case are the same (I set them up purposefully this way) so that's OK in this case.

I put in the a bit of code to output errors and trace where in the add printer component of the kix script it is and I get no output. That leads me to believe it's skipping the entire process. I'll keep checking.

Top
#74072 - 2003-03-17 06:25 AM Re: Mapping Printers by IP Subnet
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Add a catchall case to the select...endselect block.

Add as the last case:
code:
case 1
? "Failed to find IP range"

You may also wnat to add the following code to see what each IsInIPrange() returns:
code:
? "isiniprange($ipaddress,$iparray[0]) = " + isiniprange($ipaddress,$iparray[0])
? "isiniprange($ipaddress,$iparray[1]) = " + isiniprange($ipaddress,$iparray[1])
? "isiniprange($ipaddress,$iparray[2]) = " + isiniprange($ipaddress,$iparray[2])

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#74073 - 2003-03-17 06:25 AM Re: Mapping Printers by IP Subnet
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22344
Loc: OK
so, did you already remove the suggested lines?
the call-line will crash as the udf is already defined in main-script.
_________________________
!

download KiXnet

Top
#74074 - 2003-03-17 06:32 AM Re: Mapping Printers by IP Subnet
Adam Crichton Offline
Fresh Scripter

Registered: 2003-03-17
Posts: 15
Loc: Canada
Yes, the suggested lines have been removed - everything on the script looks good. I added in the code to check for errors and the following output appears:

Failed to find IP range
isiniprange(192.168.3.14,$iparray[0]) =
isiniprange(192.168.3.14,$iparray[1]) =
isiniprange(192.168.3.14,$iparray[2]) =

So it's correctly reading the IP (ie 192.168.3.14 is the client IP) but it's not actually executing the add printer functions based on that.

Top
#74075 - 2003-03-17 06:36 AM Re: Mapping Printers by IP Subnet
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I am headed to bed now. Based on your output, I would have to say that isiniprange is not returning a value. You may have to dig a little deeper.

I will check on your progress in the morning. Some of the Europeans may be able to continue working with you,
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#74076 - 2003-03-17 06:41 AM Re: Mapping Printers by IP Subnet
Adam Crichton Offline
Fresh Scripter

Registered: 2003-03-17
Posts: 15
Loc: Canada
OK thanks hopefully I can keep working with some people on it appreciate the help.
Top
#74077 - 2003-03-17 06:52 AM Re: Mapping Printers by IP Subnet
Adam Crichton Offline
Fresh Scripter

Registered: 2003-03-17
Posts: 15
Loc: Canada
OK I got it - thanks everyone for your help.

As it happened something about the select case methodlogy was the problem. When I switched it back to way I had it orginally, but with all the necessary prerequises and UDF's it worked perfectly. Is it appropriate for me to repost the code in its entirity?

Thanks so much for the help.

Top
#74078 - 2003-03-17 06:58 AM Re: Mapping Printers by IP Subnet
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22344
Loc: OK
please do so.
this way we may study the problem too [Wink]
_________________________
!

download KiXnet

Top
#74079 - 2003-03-17 07:00 AM Re: Mapping Printers by IP Subnet
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I don't understand why the select...case...endselect would be any different than the IF statements in their ability to function. I suspect something else in your code.

I am glad your code is functional though.

Feel free to post your good code as well as your non-functional code so that we can possibly determine what was wrong.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#74080 - 2003-03-17 07:23 AM Re: Mapping Printers by IP Subnet
Adam Crichton Offline
Fresh Scripter

Registered: 2003-03-17
Posts: 15
Loc: Canada
Here is the code that works. I have cut out all the misc. required UDF's; we'll assume those have been added. As you can see I have added another subnet on. Of course the select code is already in the earlier post so that's what I used; I won't reprint that here.

code:
Dim $iparray[3]

$ipaddress=@IPADDRESS0
$iparray[0]='192.168.2.0/24'
if isiniprange($ipaddress,$iparray)
$S=AddPrinterConnection ("\\diction\Woodstock Front Desk02")
$S=AddPrinterConnection ("\\woodstock02\Woodstock Label Printer")
$S=AddPrinterConnection ("\\diction\OHIP")
$S=SetDefaultPrinter ("\\diction\Woodstock Front Desk02")
ENDIF
$iparray[1]='192.168.3.0/24'
if isiniprange($ipaddress,$iparray)
$S=AddPrinterConnection ("\\diction\Stratford Front Desk02")
$S=AddPrinterConnection ("\\stratford01\Stratford Label Printer")
$S=AddPrinterConnection ("\\diction\OHIP")
$S=SetDefaultPrinter ("\\diction\Stratford Front Desk02")
ENDIF
$iparray[2]='192.168.4.0/24'
if isiniprange($ipaddress,$iparray)
$S=AddPrinterConnection ("\\goderichfrndsk\Goderich Front Desk01")
$S=AddPrinterConnection ("\\goderichfrndsk\Goderich Label Printer")
$S=AddPrinterConnection ("\\diction\OHIP")
$S=SetDefaultPrinter ("\\goderichfrndsk\Goderich Front Desk01")
ENDIF
$iparray[3]='192.168.1.0/24'
if isiniprange($ipaddress,$iparray)
$S=AddPrinterConnection ("\\diction\Cambridge Front Desk01")
$S=AddPrinterConnection ("\\diction\Cambridge Front Desk02")
$S=AddPrinterConnection ("\\diction\transcription")
$S=AddPrinterConnection ("\\diction\Mbryant Office")
$S=AddPrinterConnection ("\\diction\OHIP")
$S=AddPrinterConnection ("\\cambridge03\Clabel")
$S=SetDefaultPrinter ("\\diction\Cambridge Front Desk01")
ENDIF


Top
#74081 - 2003-03-18 12:39 AM Re: Mapping Printers by IP Subnet
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
The only thing that concerns me with this implementation passes the completed array of subnets for each IF statement. Since you add the subnet being checked right before each IF the code should work but does not sit well with me.

Maybe Sealeopard can shed some light on why the previous code did not work.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#74082 - 2003-03-17 01:25 PM Re: Mapping Printers by IP Subnet
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22344
Loc: OK
I indeed would like to see also that non-working code...
I bet that there is some little quotation or similar error...
_________________________
!

download KiXnet

Top
#74083 - 2003-03-17 03:23 PM Re: Mapping Printers by IP Subnet
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11163
Loc: Boston, MA, USA
!@#$, I just lost the answer I posted. So, now here's the short version. There was a bug in the IsInIPRange where it didn't work with a string as second parameter. The reasonwas that FOR EACH $b IN $a won't work if $a is a string. This has now beeen corrected in the UDF and an updated UDF is available at IsInIPRange() - Checks if IP address is part of a network (network ID/subnet mask) .

Adam: Please read How to use UDFs

[ 17. March 2003, 15:24: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#74084 - 2003-03-18 11:21 PM Re: Mapping Printers by IP Subnet
Adam Crichton Offline
Fresh Scripter

Registered: 2003-03-17
Posts: 15
Loc: Canada
Thanks all for your help on this - sorry for the delay in posting an update. The code that didn't work was cut and paste from the earlier message in the thread so I don't see any reason to repost it here. Still glad to see everything was straightened around and really appreciate the help. It saved a LOT of manual work.

Regards.

Top
#74085 - 2003-03-18 11:32 PM Re: Mapping Printers by IP Subnet
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22344
Loc: OK
actually, the non-working code would still be good.
as the good that you said worked is actually a wicked way to make it work.

you can use that but it's a lot harder to keep up to date than proper setup.
_________________________
!

download KiXnet

Top
Page 2 of 2 <12


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

Who's Online
0 registered and 310 anonymous users online.
Newest Members
Praveer, Ollero, rayyo, Foxlicht, DonChild
17742 Registered Users

Generated in 0.041 seconds in which 0.012 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