Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Install a printer based on range of IPs

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,46727
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Install a printer based on range of IPs
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Install a printer based on range of IPs - 5/7/2007 12:56:16 PM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
I am trying to install a tcpip printer based on the client computers IP Address Range.  Here's what I have so far.

strcomputer"."

Location1 = "a.b.1.100"
Location2 = "a.b.2.100"
Location4 = "a.b.3.100"
Location5 = "a.b.4.100"

'Create tcpip port
objNewPort.Name = "IP_" &  IP
objNewPort.Protocol = 1
objNewPort.HostAddress = IP
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = False
objNewPort.Put_

''This Installs the Driver
objshell.run "rundll32 printui.dll, PrintUIEntry /if /b " & """Printer""" & " /f c:\temp\Printer.inf /r " & Chr(34)& "IP_" & IP & Chr(34) & " /m " & """Printer"""

where I get stuck is the best way to pull the ipaddress from the client
Then how should pass the IP to the remainder of the script (create port and install driver).

in other words 
If IP address range  is a.b.1.1 to a.b.1.255  and client IP is a.b.1.120
If IP address range  is a.b.2.1 to a.b.2.255  and client IP is a.b.2.120

Then  run create port for that location and install the driver.
 
 
Post #: 1
 
 RE: Install a printer based on range of IPs - 5/7/2007 8:45:45 PM   
  Sander

 

Posts: 29
Score: 0
Joined: 10/2/2006
From: The Netherlands
Status: offline
A solution is to read the IP address from the registry.
Why do you use such a difficult method for installing a printer???
This is much easier:

Set WshNetwork = WScript.CreateObject("WScript.Network")
PrinterPath = "\\printserv\DefaultPrinter"
WshNetwork.AddWindowsPrinterConnection PrinterPath

(in reply to aburt)
 
 
Post #: 2
 
 RE: Install a printer based on range of IPs - 5/7/2007 9:43:07 PM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
These printers need to be installed locally via IP there is no print server to provide the drivers.  Also for every location the variable IP will change to the IP that corresponds to that location. 

(in reply to Sander)
 
 
Post #: 3
 
 RE: Install a printer based on range of IPs - 5/8/2007 1:09:40 AM   
  DiGiTAL.SkReAM


Posts: 1152
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: online
If you have a DNS server available to the workstations, then you could do a nslookup against that computer name and parse through the output.

_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to aburt)
 
 
Post #: 4
 
 RE: Install a printer based on range of IPs - 5/8/2007 1:16:34 AM   
  Sander

 

Posts: 29
Score: 0
Joined: 10/2/2006
From: The Netherlands
Status: offline
DHCP addresses are written in the registry too but a DNS lookup is easier.

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 5
 
 RE: Install a printer based on range of IPs - 5/8/2007 2:25:19 AM   
  dm_4ever


Posts: 2414
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
See if this helps.


      

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to aburt)
 
 
Post #: 6
 
 RE: Install a printer based on range of IPs - 5/8/2007 3:47:56 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
This works great but how can i work in the create printer port - install print driver part?


IP = Location ?

'Create tcpip port
objNewPort.Name = "IP_" &  IP
objNewPort.Protocol = 1
objNewPort.HostAddress = IP
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = False
objNewPort.Put_

''This Installs the Driver
objshell.run "rundll32 printui.dll, PrintUIEntry /if /b " & """Printer""" & " /f c:\temp\Printer.inf /r " & Chr(34)& "IP_" & IP & Chr(34) & " /m " & """Printer"""

(in reply to dm_4ever)
 
 
Post #: 7
 
 RE: Install a printer based on range of IPs - 5/8/2007 3:58:35 AM   
  dm_4ever


Posts: 2414
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
In the Select statement, instead of echoing out, assign the printers IP Address to your IP variable.

Select Case arrIPOct(2)
   Case "1"
      IP = "x.x.1.100"
....code
End Select

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to aburt)
 
 
Post #: 8
 
 RE: Install a printer based on range of IPs - 5/8/2007 4:45:24 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
Hey that works out great.  I just found out that basing the 3rd Octet on the IP address for the printer is not going to work  because we have some offices that share that Octet.  Is is possible to get a range for the last Octet.

In other words

Location1 = "a.b.1.3" to "a.b.13.31"     location 1: x.x.1.a
Location2 = "a.b.1.35" to a.b. 13.35"   location 1: x.x.1.b
Location4 = "a.b.1.67" to ""a.b. 1.94"  location 1: x.x.1.c
Location5 = "a.b.1.99" to "a.b.1.126" l ocation 1: x.x.1.d

(in reply to dm_4ever)
 
 
Post #: 9
 
 RE: Install a printer based on range of IPs - 5/8/2007 6:02:05 AM   
  mcds99


Posts: 424
Score: 4
Joined: 2/28/2006
Status: offline
Yes and no.
That is to say the network is defined on the router according to how many IP addresses are allocated for the specific VLAN.
For example: (VLAN's)
1.1.1.0 may be a /26 network with 64 IP addresses 0 - 63               = officeA
1.1.1.64 may be a /26 network with 64 IP addresses 64 - 127         = officeB
1.1.1.128 may be a /24 network with 128 IP addresses 128 - 255   = officeC

   NOTE: each VLAN could be defined on it's own router or 1 router with definition for each VLAN

So you need to know what range of addresses is used for each VLAN.

It would be easier for the end user to choose the office location with a drop down list.
Then the correct printer from a second drop down list, populated when the location is selected.

If you go the IP route get the IP address from the local machine using WMI.

      

_____________________________

Sam

Keep it Simple Make it Fun KiSMiF

(in reply to aburt)
 
 
Post #: 10
 
 RE: Install a printer based on range of IPs - 5/8/2007 6:15:05 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
I know what range all the ip are in I dont want to switch to using WMI becaue I read that IP addresses from registry are more reliable then WMI

I just want to be able to use IP ranges in the select case instead of the value for the 3rd Octet.  Can anybody help with that?

(in reply to mcds99)
 
 
Post #: 11
 
 RE: Install a printer based on range of IPs - 5/8/2007 7:57:08 AM   
  dm_4ever


Posts: 2414
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
A range might be a more difficult.....are these ranges correct:

Location1 = "a.b.1-13.3-31"   
Location2 = "a.b.1-13.35"  
Location4 = "a.b.1.67-94" 
Location5 = "a.b.1.99-126"

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to aburt)
 
 
Post #: 12
 
 RE: Install a printer based on range of IPs - 5/8/2007 12:24:16 PM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
Yes but I have more than 5 locations but I think I can edit the script if I can just get help gettng started.

Location1 = "a.b.1-13.3-31"   
Location2 = "a.b.1-13.35"  
Location3 = "a.b.1.67-94" 
Location4 = "a.b.1.99-126"

(in reply to dm_4ever)
 
 
Post #: 13
 
 RE: Install a printer based on range of IPs - 5/8/2007 1:44:40 PM   
  dm_4ever


Posts: 2414
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
See if this helps...


      

< Message edited by dm_4ever -- 5/8/2007 3:09:51 PM >


_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to aburt)
 
 
Post #: 14
 
 RE: Install a printer based on range of IPs - 5/9/2007 1:28:53 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
I think this will work but how do I pass the value to the select case

(in reply to dm_4ever)
 
 
Post #: 15
 
 RE: Install a printer based on range of IPs - 5/9/2007 2:01:57 AM   
  dm_4ever


Posts: 2414
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
You no longer use the select statement, you use this If...Else statement and assign the values to IP there.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to aburt)
 
 
Post #: 16
 
 RE: Install a printer based on range of IPs - 5/9/2007 3:53:30 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
What I trying to do is
i
f the printer is within range A use IP printer A
if the printer is with range b use IP printer B


I have to know what range the client is in before I can assign it to a particular printer.  Can you help me figure that out.

(in reply to dm_4ever)
 
 
Post #: 17
 
 RE: Install a printer based on range of IPs - 5/10/2007 12:04:02 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
After some thought and much help from you guys,  Here's  what I came up with:

What I'd like to know is

If anyone sees any problems or may be a better way to do this ( Run a Vbscript that takes the IP address of the client machine and based on the range create a specific printer port and install drivers.

Also,  What happens if the client were to run this on laptop that is not on the network.  When I disconnected my network cable and ran this script it came back with the loopback address.  Is there any way around this?  If not, maybe if the IP does not fall within the if then ranges have the script exit with an error code?


      

(in reply to aburt)
 
 
Post #: 18
 
 RE: Install a printer based on range of IPs - 5/10/2007 3:31:20 PM   
  dm_4ever


Posts: 2414
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
Like I said, you no longer use the Select Case statement because you are using the If...Else statement.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to aburt)
 
 
Post #: 19
 
 RE: Install a printer based on range of IPs - 5/11/2007 12:55:12 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
Not sure if you had a chance to look at my last script or maybe I am misundertanding but I believe I am using both If then and select case to get my desired outcome.  Do anyone have any suggestions on ways to improve script or possible the IP issue I discussed in my last post.

(in reply to dm_4ever)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Install a printer based on range of IPs Page: [1] 2   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts