jorgensen
asked on
VBS print script based on client ip
Hello,
I need a vbs script to map printers to clients based on the subnet.
The ideal way would be to have a .ini file where all the printers and subnets are defined, so the script can read from that.
.INI file:
and so on...
The only code i got so far, is the one to find the client ip-address:
strcomputer = "."
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper sonate}!\\ " & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfig uration Where IPEnabled = True")
strCount = 1
For Each objitem in colitems
If strCount = 1 Then
strIPAddress = Join(objitem.IPAddress, ",")
IP = stripaddress
strCount = strCount + 1
wscript.echo IP
Else
End If
next
I need a vbs script to map printers to clients based on the subnet.
The ideal way would be to have a .ini file where all the printers and subnets are defined, so the script can read from that.
.INI file:
[172.16]
\\sfjhsprint\lx-utred
\\sfjhsprint\lx-hs3
[172.17.1]
\\sfjhsprint\lx-rehab-lj
[172.17.84]
\\sfjhsprint\prtKilen2
[172.18.54]
\\sfjadmprint\lx-virikskole
[10]
\\sfjadmprint\prtpers
\\sfjadmprint\lx-avgift
and so on...
The only code i got so far, is the one to find the client ip-address:
strcomputer = "."
Set objFSO = CreateObject("Scripting.Fi
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfig
strCount = 1
For Each objitem in colitems
If strCount = 1 Then
strIPAddress = Join(objitem.IPAddress, ",")
IP = stripaddress
strCount = strCount + 1
wscript.echo IP
Else
End If
next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could simplify the script especially if you have subnets that are smaller than a Class C, by comparing the default gateway instead.
ASKER
Thanks for the respons jawa29.
The only problem i can see with that script is that i have 300+ printers, so it can easily get messy and hard to maintain. But now i got more to work with!
The only problem i can see with that script is that i have 300+ printers, so it can easily get messy and hard to maintain. But now i got more to work with!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.