我正在尝试创建一个脚本,该脚本将允许查看整个域中大约 1200 台机器的每台 PC 与打印机的关系。理论上,我正在寻找一个要运行的脚本,以便它将找到的所有信息发布到文本文档中,以便我们可以使用它来查看哪些 PC 连接到哪些打印机(网络/本地)。
我目前正在使用一个脚本(如下所列),它要求我输入计算机的 IP 或 PC 名称,以便它可以查询该 PC 并提供当前登录用户的当前 PC 打印机关系。
我希望在某人的帮助下更改此脚本,以便它可以查询基于文本文件或 CSV 的 PC 集合。
Const ForAppending = 8
Const ForReading = 1
Dim objTextFile
Dim objWriteFile
Dim objCopyFSO
Dim objWriteFSO
Dim objCrisFSO
Dim StrNextLine
Dim PCNameList
Dim FolderCopyError
Const ForWriting = 2
Const adTypeBinary = 1
Const adTypeText = 2
Const adSaveCreateOverWrite = 2
Const adModeReadWrite = 3
Dim sTitle, WshNetwork, objPrinter, intDrive, intNetLetter
'Tool Bar title
sTitle = "List Printers"
Dim StrComputer
'Textbox which enables the user to enter the IP/PC name of the PC
strComputer = InputBox("Enter IP or name of computer to check for " & _
"printer list (leave blank to check " & _
"local system)." & vbcrlf & vbcrlf & "Remote " & _
"checking only from NT type OS to NT type OS " & _
"with same Admin level UID & PW", sTitle)
'If the textbox is left empty then it will exit the application
If IsEmpty(strComputer) Then WScript.Quit
strComputer = Trim(strComputer)
If strComputer = "" Then strComputer = "."
'Copy the files to each workstation
'Create a new file and rename here to run multiple instances of this script.
Set WshNetwork = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objItem in colItems
UserName = objItem.UserName
arrUserName = Split(UserName, "\", -1, 1)
varUserName = arrUserName(1)
Next
filOutput = varUserName & "_printers.txt"
If objFSO.FileExists(filOutput) Then
objFSO.DeleteFile(filOutput)
End If
Set objOutputFile = objFSO.OpenTextFile (filOutput, ForAppending, True)
For Each objPrinter in colInstalledPrinters
strTest = Left(objPrinter.Name, 2)
objOutputFile.WriteLine(objPrinter.Name)
Next
'objOutputFile.Close
'added
Set objPrinter = WshNetwork.EnumPrinterConnections
'Set objOutputFile = objFSO.OpenTextFile (filOutput, ForAppending, True)
If objPrinter.Count = 0 Then
WScript.Echo "No Printers Mapped "
else
For intDrive = 0 To (objPrinter.Count -1) Step 2
intNetLetter = IntNetLetter +1
printer = "UNC Path " & objPrinter.Item(intDrive) & " = " & objPrinter.Item(intDrive +1) & " Printer : " & intDrive
objOutputFile.WriteLine(printer)
Next
end if
objOutputFile.Close
'added
varOpen = MsgBox("Do you want to view the printers?",36,"View File?")
If varOpen = vbYes Then
varCommand = "notepad " & filOutput
WshShell.Run varCommand,1,False
End If
Wscript.Sleep 1500
MsgBox "Printer mappings have been stored in '" & filOutput & "'.", 64, "Script Complete"
Wscript.Quit
这是该脚本的原始链接:http://community.spiceworks.com/scripts/show/1145-list-printers-vbs-update
如果有人有做过类似的事情的经验,或者遇到过需要收集打印机与电脑关系数据的情况,我将非常感谢您就如何最好地解决此问题提供意见。