无需用户交互即可安装网络打印机

无需用户交互即可安装网络打印机

我可以通过 .BAT 或其他自动方法安装网络打印机吗?

答案1

使用 .VBS 文件,您可以执行以下操作:

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery ("SELECT * FROM Win32_Printer")
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")

'DETERMINE OPERATING SYSTEM
For Each objOperatingSystem in colOperatingSystems               
    sOS = objOperatingSystem.Caption
    objLogFile.WriteLine "OS defined as: " & objOperatingSystem.Caption
Next

'DETERMINE THE DEFAULT PRINTER
If InStr(sOS,"2000") <> 0 Then
    For Each oPrinter in colItems 
        If oPrinter.Attributes And ATTR_DEFAULT Then
            sDefaultPrinter = oPrinter.ShareName 
        End If 
    Next
Else
    For Each objPrinter In colItems
          If objPrinter.Default Then
            sDefaultPrinter = objPrinter.ShareName
          End If
    Next
End If


'INITIALIZE THE LOCAL PRINTER OBJECTS
Set objNetwork = CreateObject("WScript.Network") 
Set objLocalPrinters = objNetwork.EnumPrinterConnections

'LOOP THROUGH YOUR PRINTERS
For iCount = 0 to objLocalPrinters.Count - 1 Step 2
If InStr(UCase(Trim(objLocalPrinters.Item(iCount+1))), "PRINTERNAMETOREMOVE") <> 0

'REMOVES PRINTERS
objNetwork.RemovePrinterConnection objLocalPrinters.Item(iCount+1)

'ADDS PRINTERS
objNetwork.AddWindowsPrinterConnection "\\[PRINT SERVER]\[PRINTER NAME]"

'IF THE PRINTER WE REMOVED WAS THE DEFAULT PRINTER, SET THE NEW ONE AS THE DEFAULT
If InStr(UCase(Trim(objLocalPrinters.Item(iCount+1))), UCase(Trim(sDefaultPrinter))) <> 0 Then
objNetwork.SetDefaultPrinter "\\[PRINT SERVER]\[PRINTER NAME]"
End If

End If
Next

答案2

看起来这是您想要在批处理脚本中使用的命令:

prncfg

事先检查文档:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prncnfg.mspx

相关内容