0

首先,我是脚本世界的新手。我做了一个将 TCP/IP 打印机(在网络中)添加到计算机的 VBScript。到目前为止,我还设法更改打印机以使用批处理文件执行双面打印。现在我需要以某种方式更改打印机颜色设置以进行黑白打印。

如果您能帮助我,我将不胜感激,在此先感谢。

将 tcp/ip 打印机添加到计算机的代码:

 strComputer = "."
Dim objWMI:Set objWMI = GetObject("winmgmts://" & strComputer & "\root\cimv2") 
Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem", , 48)

Set objWMIService = GetObject("winmgmts:" _   
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")       
    objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True


Install "167.221.10.249" ''printer IP to be added

sub Install(strIP) 
    InstallPrinterPort strIP
end Sub

strBasePrinter = "PRINTERNAME"
strPrinterName = "Xerox WorkCentre 7120 PCL6" '' Printer controller
strINFPath = "\\167.221.1.67\printer_7120\x2GCHAX.inf" ''path to .inf file

strIPPort = "IP_" & "167.221.10.249"
Set objShell = CreateObject("WScript.Shell")
strCommand = "cmd /c rundll32 printui.dll,PrintUIEntry /if /b """ & strBasePrinter &    """ /f " & strINFPath & " /r """ & strIPPort & """ /m """ & strPrinterName & """ & /Z"
objShell.Run strCommand, 1, True

Sub InstallPrinterPort(strIP)

Set colInstalledPorts =  objWMIService.ExecQuery _        
    ("Select Name from Win32_TCPIPPrinterPort")

For each objPort in colInstalledPorts
    If objPort.Name="IP_" & strIP then exit sub     
Next

Set objNewPort = objWMIService.Get _
    ("Win32_TCPIPPrinterPort").SpawnInstance_
        objNewPort.Name = "IP_" & strIP
        objNewPort.Protocol = 1
        objNewPort.HostAddress = strIP
        objNewPort.PortNumber = "9100"
        objNewPort.SNMPEnabled = True
        objNewPort.Put_ 
end Sub
4

1 回答 1

-2

在我的研究中,我发现了这一点。我相信它将打印机设置为默认颜色。

Option Explicit
Dim objPrinter
Set objPrinter = CreateObject("WScript.Network")
objPrinter.SetDefaultPrinter "\\ServerName\PrinterName"
' End of example VBScript 
于 2013-06-03T09:32:08.337 回答