1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
Select Case GetAdressip
Case "AdressA"
WScript.Echo "Add Printer A"
MapNetworkPrinter "UNC Path imprimante A"
Case "AdressB"
WScript.Echo "Add Printer B"
MapNetworkPrinter "UNC Path imprimante B"
Case "AdressC"
WScript.Echo "Add Printer C"
MapNetworkPrinter "UNC Path imprimante C"
Case Else
WScript.Echo "Réseau non reconnu"
End Select
Private Function GetAdressip()
'local var
Dim objWMIService,ColNetworks,NetworkItem
Dim strIPAddress
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set ColNetworks = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled = true",,48)
For Each NetworkItem in ColNetworks
strIPAddress = NetworkItem.IPAddress(0)
Next
Set objWMIService = Nothing
Set ColNetworks = Nothing
GetAdressip = strIPAddress
End Function
Private Sub MapNetworkPrinter(UNCPrinter)
'local var
Dim ObjNetwork
Set ObjNetwork = CreateObject("WScript.Network")
ObjNetwork.AddWindowsPrinterConnection UNCPrinter
Set ObjNetwork = Nothing
End Sub |
Partager