标题: [问题求助] VBS脚本自动安装网络打印机,能不能改为根据“mac地址”来安装? [打印本页]
作者: zhangop9 时间: 2012-7-27 11:47 标题: VBS脚本自动安装网络打印机,能不能改为根据“mac地址”来安装?
在局域网中机器名有时会变,只有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
复制代码
作者: zhangop9 时间: 2012-7-27 12:26
- rem 等号后输入你知道的MAC地址
- set MAC=00-00-00-00-00-00
- rem 等号后输入你的网段
- set 网段=192.168.0.
- for /l %%i in (1,1,254) do ping %网段%%%i -w 10 -n 1
- for /f "tokens=1* delims=: " %%i in ('arp -a^|find /i "%mac%"') do set ip=%%i
- for /f "tokens=1* delims=:<> " %%j in ('nbtstat -a %ip%^|find /i "unique"') do if %%j == WORKGROUP (echo .)else echo %%j>找到的计算机.txt
复制代码
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |