Board logo

标题: [问题求助] VBS脚本自动安装网络打印机,能不能改为根据“mac地址”来安装? [打印本页]

作者: zhangop9    时间: 2012-7-27 11:47     标题: VBS脚本自动安装网络打印机,能不能改为根据“mac地址”来安装?

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

作者: zhangop9    时间: 2012-7-27 12:26

  1. rem 等号后输入你知道的MAC地址
  2. set MAC=00-00-00-00-00-00
  3. rem 等号后输入你的网段
  4. set 网段=192.168.0.
  5. for /l %%i in (1,1,254) do ping %网段%%%i -w 10 -n 1
  6. for /f "tokens=1* delims=: " %%i in ('arp -a^|find /i "%mac%"') do set ip=%%i
  7. for /f "tokens=1* delims=:<> " %%j in ('nbtstat -a %ip%^|find /i "unique"') do if %%j == WORKGROUP (echo .)else echo %%j>找到的计算机.txt
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2