检查是否存在打印机连接(不可靠的打印机映射)

我有一个实验室,里面有大约75个XP盒子。 login时,我们使用VBS中的AddWindowsPrinterConnection方法映射两台服务的打印机。 5-10%的时间,用户发现打印机没有成功映射,他们的打印作业失败。 如果他们重新启动或注销,则打印机通常会在第二次尝试中成功映射。

我想添加逻辑到我的脚本来检查打印机映射是否正确,如果没有,重新运行AddWindowsPrinterConnection命令 – 但我不知道如何以编程方式检查打印机对象是否已被映射。

还是有一个更可靠的策略来映射多个打印机持续这些configuration文件? login脚本仍然是最好的办法吗?

看看下面的脚本。 它报告当前分配的打印连接。 这应该足以让你开始重新:你自己的脚本,我会想。

OPTION EXPLICIT Dim oNetwork ' WScript.Network object Dim colPrinters ' A collection of the users printer connections Dim x ' The canonical scratch variable of doom! On Error Resume Next Set oNetwork = CreateObject("WScript.Network") Set colPrinters = oNetwork.EnumPrinterConnections ' Iterate thru the collection of printers for x = 1 to colPrinters.count Step 2 WScript.Echo "Printer: '" & colPrinters(x) & "' on port '" & colPrinters(x - 1) & "'" next set oNetwork = Nothing set oShell = Nothing 

您可能还希望使用作为Windows资源工具包一部分的打印机pipe理工具(prnadmin.dll) 。 它可以更好地控制打印机在特定系统或用户configuration文件中的内容。