楼上的太不厚到了,好东西不给大家看.
请看我这边的脚本,登陆不同的地方添加不同地方的打印机
在其中我把各地方装有打印机的服务器名字改成server1---5,没办法,不能泄露,万一被别人黑了怎么办,哈哈
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\"& strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each observer5apter in colAdapters
If Not IsNull(observer5apter.IPAddress) Then
For i = 0 To UBound(observer5apter.IPAddress)
if left(observer5apter.IPAddress(i),10)="192.168.0." then loc="MC"
if left(observer5apter.IPAddress(i),10)="192.168.10" then loc="DU"
if left(observer5apter.IPAddress(i),10)="192.168.40" then loc="BA"
if left(observer5apter.IPAddress(i),10)="192.168.50" then loc="LD"
if left(observer5apter.IPAddress(i),10)="192.172.0." then loc="SH"
Next
End If
Next
'WScript.Echo "Location is " & loc
On Error Resume Next
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer where Network = 1")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next
dim wshnetwork
if loc = "MC" Then
set wshnetwork=wscript.createobject("wscript.network")
wshnetwork.addwindowsprinterconnection "[url=file://\\server1\Xerox]\\server1\Xerox[/url] DC240 Black"
wshnetwork.setdefaultprinter "[url=file://\\server1\Xerox]\\server1\Xerox[/url] DC240 Black"
wshnetwork.addwindowsprinterconnection "[url=file://\\server1\Xerox]\\server1\Xerox[/url] DC240 Color"
wshnetwork.addwindowsprinterconnection "[url=file://\\server1\Canon]\\server1\Canon[/url] iR3100 Black"
wshnetwork.addwindowsprinterconnection "[url=file://\\server1\Canon]\\server1\Canon[/url] iR3100 Color"
wshnetwork.addwindowsprinterconnection "[url=file://\\server1\HPLJ2600B]\\server1\HPLJ2600B[/url]"
wshnetwork.addwindowsprinterconnection "[url=file://\\server1\HPLJ2600C]\\server1\HPLJ2600C[/url]"
end If
if loc = "DU" Then
set wshnetwork=wscript.createobject("wscript.network")
wshnetwork.addwindowsprinterconnection "[url=file://\\server2\XeroxPro35]\\server2\XeroxPro35[/url]"
wshnetwork.setdefaultprinter "[url=file://\\server2\XeroxPro35]\\server2\XeroxPro35[/url]"
wshnetwork.addwindowsprinterconnection "[url=file://\\server2\XeroxPhaser]\\server2\XeroxPhaser[/url]"
end If
if loc = "BA" Then
set wshnetwork=wscript.createobject("wscript.network")
wshnetwork.addwindowsprinterconnection "[url=file://\\server3\Canon2200B]\\server3\Canon2200B[/url]"
wshnetwork.setdefaultprinter "[url=file://\\server3\Canon2200B]\\server3\Canon2200B[/url]"
wshnetwork.addwindowsprinterconnection "[url=file://\\server3\Canon2200F]\\server3\Canon2200F[/url]"
end If
if loc = "LD" Then
set wshnetwork=wscript.createobject("wscript.network")
wshnetwork.addwindowsprinterconnection "[url=file://\\server4\XeroxPro45]\\server4\XeroxPro45[/url]"
wshnetwork.setdefaultprinter "[url=file://\\server4\XeroxPro45]\\server4\XeroxPro45[/url]"
end If
if loc = "SH" Then
set wshnetwork=wscript.createobject("wscript.network")
wshnetwork.addwindowsprinterconnection "[url=file://\\server5\xerox]\\server5\xerox[/url]"
wshnetwork.setdefaultprinter "[url=file://\\server5\xerox]\\server5\xerox[/url]"
wshnetwork.addwindowsprinterconnection "[url=file://\\server5\ricoh]\\server5\ricoh[/url]"
wshnetwork.addwindowsprinterconnection "[url=file://\\server5\kyocera]\\server5\kyocera[/url]"
end If