Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


This script maps printers according to the computers subnet/ default gateway

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> This script maps printers according to the computers subnet/ default gateway
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 This script maps printers according to the computers su... - 1/23/2006 7:13:24 PM   
  centrino

 

Posts: 16
Score: 0
Joined: 9/4/2005
Status: offline
' This script maps printers according to the computers subnet/ default gateway

 Option Explicit
Dim dPrtLst
Set dPrtLst=CreateObject("Scripting.Dictionary")
On Error Resume Next

 ' ###### LOCATIO1  ######
 dPrtLst.Add "10.16.16.254",   Array("\\hihhps01\hihhpr003","\\hihhps01\hihhpr004","\\hihhps01\hihhpr023","\\hihhps01\hihhpr024","\\hihhps01\hihhpr025")
dPrtLst.Add "10.16.17.254",   Array("
\\hihhps01\hihhpr001","\\hihhps01\hihhpr002","\\hihhps01\hihhpr004","\\hihhps01\hihhpr005","\\hihhps01\hihhpr006","\\hihhps01\hihhpr026")
dPrtLst.Add "10.16.18.254",   Array("
\\hihhps01\hihhpr014","\\hihhps01\hihhpr015","\\hihhps01\hihhpr016","\\hihhps01\hihhpr017","\\hihhps01\hihhpr018","\\hihhps01\hihhpr019","\\hihhps01\hihhpr020","\\hihhps01\hihhpr021","\\hihhps01\hihhpr022")
dPrtLst.Add "10.16.19.254",   Array("
\\hihhps01\hihhpr007","\\hihhps01\hihhpr008","\\hihhps01\hihhpr009","\\hihhps01\hihhpr010","\\hihhps01\hihhpr011","\\hihhps01\hihhpr012","\\hihhps01\hihhpr013","\\hihhps01\hihhpr027")
 ' ###### LOCATION 1 ######
 dPrtLst.Add "10.48.64.254",   Array("\\hisaps01\hihwpr001","\\hisaps01\hihwpr002","\\hisaps01\hihwpr003","\\hisaps01\hihwpr004","\\hisaps01\hihwpr005","\\hisaps01\hihwpr006","\\hisaps01\hihwpr007","\\hisaps01\hihwpr008","\\hisaps01\hihwpr009","\\hisaps01\hihwpr0010","\\hisaps01\hihwpr011","\\hisaps01\hihwpr012","\\hisaps01\hihwpr013","\\hisaps01\hihwpr014","\\hisaps01\hihwpr015","\\hisaps01\hihwpr016","\\hisaps01\hihwpr017","\\hisaps01\hihwpr018","\\hisaps01\hihwpr019","\\hisaps01\hihwpr020","\\hisaps01\hihwpr021")
 MapPrinters(GetSubnet)
Function GetSubnet
Dim WMI,NICs,NIC
Set WMI=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set NICs=WMI.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True")
GetSubnet=""
For Each NIC In NICs
 If Not IsNull(NIC.DefaultIPGateway)Then
  GetSubnet=NIC.DefaultIPGateway(0)
  Exit Function
 End If
Next
End Function

Sub MapPrinters(sSubNet)
Dim sPrtName,NET
If sSubNet<>"" Then
 If dPrtLst.Exists(sSubNet) Then
  Set NET=CreateObject("WScript.Network")
  For Each sPrtName In dPrtLst.Item(sSubNet)
   NET.AddWindowsPrinterConnection sPrtName
  Next
 End If
End If
End Sub
 
 
Post #: 1
 
 RE: This script maps printers according to the computer... - 1/24/2006 3:30:53 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Three suggestions:
1) You should use a code block when posting code.
2) One space does not make much of an indent to make the code more legible.
3) You should indent all code blocks.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to centrino)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> This script maps printers according to the computers subnet/ default gateway Page: [1]
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