Page 1 of 2 12>
Topic Options
#183420 - 2007-12-08 02:18 PM Install Printers using IP?? Is it possible
rhunton Offline
Fresh Scripter

Registered: 2007-12-08
Posts: 11
Loc: York, United Kingdom
Hi All,
I am a complete n00b to kixtart scripting.
I am not sure where to ask this question or if it is at all possible!!
This is what I have at the moment.

Dim $defaultgw
$defaultgw = EnumIPInfo($NIC,3)
If $defaultgw == '192.168.1.1'
"Your Default Gateway is: " + EnumIPInfo($NIC,3)
USE K: '\\servername\servershare'
else if $defaultgw == '192.168.2.1'
USE L: '\\servername\servershare'

Now the problem I have now is I would like kix to install a printer on the detected network subnet.
This would involve creating a new TCP/IP printer port and then installing the drivers.
eg if 192.168.1.1 was detected it would install 192.168.1.2

Has anyone got any ideas on how to do this?
The script would be rolled out to around 400 desktops and 350 laptops if it is possible!!!

Thanks for your help


Edited by rhunton (2007-12-08 02:43 PM)

Top
#183424 - 2007-12-08 04:00 PM Re: Install Printers using IP?? Is it possible [Re: rhunton]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
750 computers all doing unmanaged printing! Why? Why not manage them with print servers?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#183425 - 2007-12-08 04:23 PM Re: Install Printers using IP?? Is it possible [Re: rhunton]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Addprinterconnection() is the way to connect to NT Based print servers, and in most cases is the preferred way of doing things. Once the printer is setup on the server correctly, and then shared, it is simply a matter of using addprinterconnection. The configuration of the printer, and its drivers come over when you add the connection. It is built into kix. See the manual for further explanation.

Addprinter()is a User Defined Function. It provides a way to add a Local printer (including IP, LPT, COM) to a workstation. To install, it requires the print drivers be available, either on the pc or on the network. The user installing/running the script must be an Administrator of the PC. You also have to define the port, the name, amongst other settings. Addprinter() can be found here: http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=84165#Post84165

Top
#183426 - 2007-12-08 04:43 PM Re: Install Printers using IP?? Is it possible [Re: Allen]
rhunton Offline
Fresh Scripter

Registered: 2007-12-08
Posts: 11
Loc: York, United Kingdom
Thanks for the help; I will give that a stab.
I maybe should have said the computers are distributed throughout the UK. We have several regional offices and about 50 building sites all connected back with ADSL.
Depending on the site we may only have 2 PC’s to 1 printer others can have 15 PC’s to 1 printer.
I will work on it and the bigger sites may just warrant a print servers

Cheers Guys

Top
#183431 - 2007-12-08 11:44 PM Re: Install Printers using IP?? Is it possible [Re: rhunton]
rhunton Offline
Fresh Scripter

Registered: 2007-12-08
Posts: 11
Loc: York, United Kingdom
Help with AddPrinter() - Add IP,LPT, or COM Printers.

I have been playing about with the script that you advised me to use but am unable to make any use of it.

The part that I am finding hard to understand is when a line starts with a; - does that mean its commented out. It does in VB?
Also, in the script where do you declare all the information? Is it all under the parameters section that I though was commented out?

Top
#183432 - 2007-12-09 12:22 AM Re: Install Printers using IP?? Is it possible [Re: rhunton]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Yes a ; is a comment mark - as for the parameters those are what are passed into the UDF

In this particular case
AddPrinter(192.168.0.100,"HP400M","C:\Drivers\HP.INF","Secretary Pool",,1)

Would add a printer on port 192.168.0.100 The Inf file would have the printer listed in it as HP400M and the INF file is located at C:\Drivers, the description on the printer is Secretary Pool, it will be installed on the local machine and will be set as default.

Does this help?
_________________________
Today is the tomorrow you worried about yesterday.

Top
#183438 - 2007-12-09 11:01 AM Re: Install Printers using IP?? Is it possible [Re: Gargoyle]
rhunton Offline
Fresh Scripter

Registered: 2007-12-08
Posts: 11
Loc: York, United Kingdom
Hi, thanks for the reply.
I just need one last bit of help please.

When you are defining the informtion, how do you format it?
for example take $port =
Does the information have to be contained between the brackets or do you just type 192.168.1.1, "192.168.1.1", (192.168.1.1), ("192.168.1.1")

I think once I know the answer to this it should be pretty stright forward

;Parameters:
; $Port = "192.168.1.1"
; IPAddress(RAW) (xxx.xxx.xxx.xxx)
; IPAddress(LPR) (xxx.xxx.xxx.xxx:LPRQueueName)
; LPT (LPT1:)
; COM (COM1:)
; PrintServer (\\server\printer)

Thanks again

Top
#183439 - 2007-12-09 03:44 PM Re: Install Printers using IP?? Is it possible [Re: rhunton]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Don't modify anything inside the UDF. Pass them as parms. All strings should be quoted. Allen provided four examples!
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#183440 - 2007-12-09 05:03 PM Re: Install Printers using IP?? Is it possible [Re: Les]
rhunton Offline
Fresh Scripter

Registered: 2007-12-08
Posts: 11
Loc: York, United Kingdom
Thanks for the help guys. All working now!!

Is it possible to skip a printer install if it is currently installed?
When I run the script I end up with printer1, printer1 (copy 1), printer1 (copy2) etc.

Thanks

Top
#183441 - 2007-12-09 05:08 PM Re: Install Printers using IP?? Is it possible [Re: rhunton]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Yup... See PrinterExist() http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=84400#Post84400
Top
#183442 - 2007-12-09 08:56 PM Re: Install Printers using IP?? Is it possible [Re: Allen]
rhunton Offline
Fresh Scripter

Registered: 2007-12-08
Posts: 11
Loc: York, United Kingdom
Hi All,
On a seperate note how would I do the following?
I would like to pass the result of EnumIPInfo($NIC,3) into a variable.

This is what I have at the moment

Dim $defaultgw
$defaultgw = EnumIPInfo($NIC,3)

If $defaultgw == '192.168.1.1'
"Your Default Gateway is:" + EnumIPInfo($NIC,3)
call "another kix script"
else
endif
If $defaultgw == '192.168.2.1'
else
endif

Have I got the part correct about passing the result of EnumIPInfo($NIC,3) into the variable?

Thanks


Edited by rhunton (2007-12-09 09:05 PM)

Top
#183443 - 2007-12-09 09:35 PM Re: Install Printers using IP?? Is it possible [Re: rhunton]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
What is $NIC, why are you forcing case with ==, and why the empty ELSE sections?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#183444 - 2007-12-09 10:19 PM Re: Install Printers using IP?? Is it possible [Re: Les]
rhunton Offline
Fresh Scripter

Registered: 2007-12-08
Posts: 11
Loc: York, United Kingdom
Hi Les,
The $NIC is querying my network card information.

The idea to the script:
When I get a user plugs into one of our remote networks for the first it will install the printers for that network on the users pc.

I just remember from my Visual Basic days at college that == worked and I just gave it a try - i am guessing that = will work just as well.

Will I get away without putting else statements in the code?

I have got the code running now and thanks to the scripts from Allen all is working great.

I have no doubt that I will run into problems in the future so will be in contact again.

Thanks All

Rob


Edited by rhunton (2007-12-09 10:19 PM)

Top
#183445 - 2007-12-09 10:40 PM Re: Install Printers using IP?? Is it possible [Re: rhunton]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I don't see where you set any value to $NIC. How and where do you determine what value to assign to $NIC?

In KiX, == forces a case sensitive =.

ELSE is not needed if there is no ELSE condition.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#183446 - 2007-12-09 10:56 PM Re: Install Printers using IP?? Is it possible [Re: Les]
rhunton Offline
Fresh Scripter

Registered: 2007-12-08
Posts: 11
Loc: York, United Kingdom
The EnumIPInfo($NIC,3) is calling information from my network card. IE Static address or DHCP Address
From what I read;
EnumIPInfo($NIC,1) = IP Address
EnumIPInfo($NIC,2) = Subnet Mask
EnumIPInfo($NIC,3) = Default Gate

I just googled the problem it turned up that code.

I have now got to implement it in an Active directory to see what the result is.

Hope the above is use to other people.


Edited by rhunton (2007-12-09 10:57 PM)

Top
#183447 - 2007-12-09 11:09 PM Re: Install Printers using IP?? Is it possible [Re: rhunton]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Still, I don't see where you assign any value to $NIC! You should not rely on blind faith that $NIC will somehow magically have a suitable value.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#183448 - 2007-12-09 11:28 PM Re: Install Printers using IP?? Is it possible [Re: Les]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You take the time to Dim $defaultgw but then use an undefined var $NIC.

Essentially, your code is:
$defaultgw = EnumIPInfo(,3)
or:
$defaultgw = EnumIPInfo(0,3)

It is only by the good grace of Ruud and his forgiving code that lets you get away with it. What if 0 isn't the NIC index you need? Your code is too optimistic.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#183464 - 2007-12-10 04:37 PM Re: Install Printers using IP?? Is it possible [Re: Les]
rhunton Offline
Fresh Scripter

Registered: 2007-12-08
Posts: 11
Loc: York, United Kingdom
Hi Les,
Thanks for that.
I realized that when you have multiple network cards like in a laptop you need to query all of them to see which is connected.
The script now runs:

 Code:
Dim $defaultgw0
Dim $defaultgw1
Dim $defaultgw2
$defaultgw0 = EnumIPInfo(0,3)
$defaultgw1 = EnumIPInfo(1,3)
$defaultgw2 = EnumIPInfo(2,3)

If $defaultgw0 = '192.168.1.1' or $defaultgw1 ='192.168.1.1' or $defaultgw2 ='192.168.1.1'
call file.kix


Works a treat now and it works with laptops and desktop.

I see where you were coming from now.


Thanks!!


Edited by rhunton (2007-12-11 12:04 PM)

Top
#183465 - 2007-12-10 06:26 PM Re: Install Printers using IP?? Is it possible [Re: rhunton]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
There is no need for the double =. Like Les already said = = does a case sensitive =. An IP address has no upper or lower case so = will work just great.

Can you use code tags the next time you post some code? It is much easier to read a script that way especially when it is a larger script then you have now because the formatting gets preserved
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#183491 - 2007-12-11 04:36 PM Re: Install Printers using IP?? Is it possible [Re: Mart]
rhunton Offline
Fresh Scripter

Registered: 2007-12-08
Posts: 11
Loc: York, United Kingdom
Hi All,
I have been looking at the DelPrinterConnection() but it looks like it will not remove the local printers.

I can get rid of the network ones - thats great but ideally need a scipt that will work with local printers as well.

I know that this command works:
 Code:
if printerexist("OKI B4350 (Test Printer1)")
  run '%COMSPEC% /C START rundll32 printui.dll,PrintUIEntry /dl  /n "OKI B4350 (Test Printer1)"
endif

but would like to keep all the kix scripts kixy not having to call cmd commands in the middle of scripts.

Also if I use the above code I get windows shouting at me saying that it is not installed or has been removed.

Thanks


Edited by rhunton (2007-12-11 04:52 PM)

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
2 registered (morganw, mole) and 414 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.073 seconds in which 0.021 seconds were spent on a total of 14 queries. Zlib compression enabled.

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