我有一个要求,即通过组策略,所有客户端计算机都需要安装一个名为“PostScript 打印机”的打印机,我在网上找到的每个示例都是安装网络打印机(这不是我想要的)。
任何帮助,将不胜感激。
谢谢。
答案1
以下代码对我有用。虽然不完美,但确实有效。
Option Explicit
'On Error Resume Next
Dim oWshShell, objWMIService
Set oWshShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Function PrinterExists(PrinterName)
Dim colPrinters, objPrinter
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where DeviceID = '" & PrinterName & "'")
PrinterExists = False
For Each objPrinter in colPrinters
PrinterExists = True
Next
End Function
Sub RenamePrinter(NameBefore, NameAfter)
Dim colPrinters, objPrinter
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where DeviceID = '" & NameBefore & "'")
For Each objPrinter in colPrinters
objPrinter.RenamePrinter(NameAfter)
Next
End Sub
Function InstallPrinter(PrinterName)
If Not PrinterExists(PrinterName) Then
Installing = oWshShell.Run("rundll32 printui.dll PrintUIEntry /if /f %windir%\inf\ntprint.inf /r ""file:"" /m """ & PrinterName & """")
End If
Dim FailCount
FailCount = 0
Do While Not PrinterExists(PrinterName) And FailCount < 5
WScript.Sleep 1000
FailCount = FailCount + 1
Loop
InstallPrinter = PrinterExists(PrinterName)
End Function
Dim Installing
If Not PrinterExists("PostScript Printer") Then
'XP makes this apple printer available
If InstallPrinter("Apple Color LW 12/660 PS") Then
RenamePrinter "Apple Color LW 12/660 PS", "PostScript Printer"
Else
'Don't know of a vista one yet
End If
End If