|
|
![]() |
|
|
Top | #1 |
|
OSNN Junior Addict
Joined: January 2006
Posts: 45
Reputation: 0
Power: 74 |
im trying to create a login script that will install the proper printers based on your ip currently we use two ip ranges 192.168.100.0 and 192.168.0.0 right now im trying to get this to work with 1 network, then i will introduce the second network once i get this working currently the scrip works but only if it compares to 1 ip, cant figure out how to have it check,, idealy i would like it to do this.. compare ip to 192.168.100.* or 192.168.0.* or what ever the case maybe. Code:
Dim strComputer
Dim objWMIService
Dim colItemSet
Dim colItem
Dim i
Dim wNetwork
Dim printerPath
Dim printerPath2
Dim printerPath3
Dim printerPath4
strComputer = "."
On Error Resume Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
On Error GoTo 0
If Not (objWMIService Is Nothing) Then
Set colItemSet = objWMIService.execQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each colItem In colItemSet ' There should only be one active one
If Not IsNull(colItem.IPAddress) Then
For i = LBound(colItem.IPAddress) To UBound(colItem.IPAddress)
If colItem.IPAddress(i) <> "0.0.0.0" Then 'any other connections to a PC such as bluetooth create a blank IP
If colItem.IPAddress(i) = "192.168.100.104" Then
Set wNetwork = WScript.CreateObject("WScript.Network")
printerPath = "\\sam1\KM-200"
wNetwork.AddWindowsPrinterConnection printerPath
printerPath2 = "\\sam1\KM-250"
wNetwork.AddWindowsPrinterConnection printerPath2
printerPath2 = "\\sam1\KM-350"
wNetwork.AddWindowsPrinterConnection printerPath2
printerPath2 = "\\sam1\KM-420"
wNetwork.AddWindowsPrinterConnection printerPath2
WScript.Quit
End If
End If
Next
End If
Next
End If
|
|
|
|
|
|
Top | #2 |
|
XPista7eopard*ix
Joined: April 2004
Location: Chicagoland
Posts: 4,014
Reputation: 2947
Power: 164 |
Oi what a mess.. give me a couple hours and I'll post something cleaner
question: why are you using the goto 0 statement in vbscript? VB != VBScript and, in general, is not the way to handle errors in VBScript.. that line will turn error trapping off.. edit: try this: Code:
Dim strComputer,strIPAddress,strIPRange
Dim objNetwork
Dim IPConfigSet, IPConfig
Dim arrIPAddress
strComputer = "."
Set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" _
& strComputer & "/root/cimv2").ExecQuery("select IPAddress from " _
& "Win32_NetworkAdapterConfiguration where IPEnabled=True")
Set objNetwork = WScript.CreateObject("WScript.Network")
For Each IPConfig In IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
arrIPAddress = split(IPConfig.IPAddress(0) ,".")
strIPRange = arrIPAddress(0) & "." & arrIPAddress(1) & "." & arrIPAddress(2) & ".0"
select case strIPRange
case "192.168.100.0"
objNetwork.AddWindowsPrinterConnection "\\server\printer"
case "192.168.0.0"
objNetwork.AddWindowsPrinterConnection "\\server\printer"
end select
end if
next
set objNetwork = nothing
set IPConfigSet = nothing
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| VBS script to check printer status | j79zlr | Web Design & Coding | 3 | March 28th, 2008 1:56am |
| Domain group policy login script not applying | Mainframeguy | Windows Desktop Systems | 1 | October 8th, 2007 7:45pm |
| Login Script Help | kcnychief | Windows Server Systems | 2 | January 18th, 2007 4:45am |
| Login Script Syntax | kcnychief | Windows Server Systems | 10 | March 12th, 2006 4:30am |
| News script needed PHP/Mysql based | stewartbmw2000 | Web Design & Coding | 1 | August 21st, 2002 3:13pm |