需要帮助从多个联网计算机中获取打印机名称,型号和驱动程序编号。 [英] Need help with grabbing a printer name, model, and driver number from several networked machines.

查看:85
本文介绍了需要帮助从多个联网计算机中获取打印机名称,型号和驱动程序编号。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我有一个脚本,我已经找到并修改,以满足我的需求,但我似乎无法让它运行正常。我需要从网络上的几台机器上获取2台打印机的名称,它们的型号以及它们的驱动程序名称和修订版本。这将是我在VB中编写代码的第一次尝试,我在大约10年内没有任何编码经验。任何建议都会受到极大的反对!



Hi. I have a script that I have found and modified to fit my needs but I can not seem to get it to run properly. I need to grab the name of 2 printers, their model numbers, along with their driver name and revision from several machines on my network. This will be my first attempt at coding in VB and I have not had any coding experience in ~10 years. Any suggestions would be greatly aprreciated!

On Error Resume Next

Const ForAppending = 8 
Const ForReading = 1 

Dim WshNetwork, objPrinter, intDrive, intNetLetter, objDriver
arrComputers = Array("here is where the list of computers goes")

Set WshNetwork = CreateObject("WScript.Network") 
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer",,48)
Set colInstalledDrivers =  objWMIService.ExecQuery("Select * from Win32_PrinterDriver",,48)
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48) 
Set WshShell = WScript.CreateObject("WScript.Shell") 
Set objFSO = CreateObject("Scripting.FileSystemObject") 


For Each strComputer In arrComputers

	For Each objItem in colItems 
	UserName = objItem.UserName 
	arrUserName = Split(UserName, "\", -1, 1) 
	varUserName = arrUserName(1) 
	Next 

filOutput = varUserName & ".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 "Name: "& (objPrinter.Name) 
For Each objDriver in colInstalledDrivers
strTest = Left(objDriver.Name, 2)
objOutputFile.WriteLine "Driver Name: " &(objDriver.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
Next
Next

推荐答案

我认为所有这些东西需要去里面 For..Next循环:



I think all this stuff needs to go inside the For..Next loop:

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer",,48)
Set colInstalledDrivers =  objWMIService.ExecQuery("Select * from Win32_PrinterDriver",,48)
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)







?


这篇关于需要帮助从多个联网计算机中获取打印机名称,型号和驱动程序编号。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆