在局域网中机器名有时会变,只有mac地址少变动,所以我想通过mac地址找到机器名后,再安装网络打印机不知这个方法是否可行,楼下是根据mac找机器名供参考!- ' -------------------------------------------------
- ' fileName - Printer.vbs
- ' -------------------------------------------------
- ' 作用: 脚本自动安装网络打印机
- ' 作者: hank, [QQ 635352]
- ' 日期: 10:08 2009年11月06日
- ' 版本: 1.0.0.0
- ' -------------------------------------------------
- Option Explicit
- On Error Resume Next
- Const ServerName="Server09" ‘根据“mac地址”来安装
- Const UserPassword="1860"
- Const UserName="PrintUser"
- Const ShareName="hp128000"
- Dim printerPath, strComputer
- Dim wshNetwork, oRun, oShell, wenv
- Set wshNetwork = WScript.Createobject("WScript.Network")
- Set oShell = Createobject("WScript.Shell")
- 'Set wenv=oShell.EnvironMent("PROCESS")
- oRun = oShell.Run("NET USE \\"&ServerName&"\ipc$ "&UserPassword&" /USER:"&UserName&" /PERSISTENT:yes", 0, True)
- If Not oRun=0 Then
- MsgBox vbLf & vbLf & "与共享打印机连接失败, 请查证网络用户密码是否正确?" & vbLf & vbLf, 64, "建立连接失败"
- WScript.Quit
- End If
- 'Map Printer
- PrinterPath = "\\" & ServerName & "\" & ShareName
- wshNetwork.AddWindowsPrinterConnection PrinterPath
- wshNetwork.SetDefaultPrinter PrintPath
- 'Delete Printer
- 'wshNetwork.RemovePrinterConnection PrinterPath, True
- Dim objWMIService, colItems, objItem
- 'strComputer = wenv("ComputerName")
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
- Set colItems = objWMIService.ExecQuery("SELECT DeviceID, DriverName FROM Win32_Printer",, 48)
- For Each objItem in colItems
- If InStr(objItem.DeviceID, serverName)>0 Then
- MsgBox vbLf & vbLf &"恭喜:已安装好打印机: " & objItem.DriverName & vbLf & vbLf, 64, "本地打印机"
- WScript.Quit
- End If
- Next
- MsgBox vbLf & vbLf & "未能成功安装网络打印机:"&ShareName&" 请检查安装权限!" & vbLf & vbCrLf, 64, "安装打印机"
- WScript.Quit
复制代码
|