2

我收到错误

pywintypes.error: (1801, 'AddPrinter', 'The printer name is invalid.')

我的意图是将网络打印机添加到最终用户计算机...这是我的定义

import win32print

def AddPrinter(computer, printer):
    pHandle = win32print.OpenPrinter(printer) #int
    print "%s = %s"%(printer, pHandle)

    pInfo = win32print.GetPrinter(pHandle,2) #dict
    print pInfo

    win32print.ClosePrinter(pHandle)    

    win32print.AddPrinter(computer, 2, pInfo)

if __name__=='__main__':
    computer = 'remote-pc'
    printer = r'\\printserver\printer1'
    AddPrinter(computer, printer)

这是怎么回事...它必须是一个有效的打印机名称,因为它成功地拉动了手柄并给了我它想要的 pInfo 字典...令人沮丧...我不想制作任何批处理文件!

感谢您提供的任何帮助。

追溯:

    \\cheops1\4EPrint1 = <PyPrinterHANDLE:4704604>
    {'Status': 0, 'UntilTime': 0, 'pDriverName': 'HP Universal Printing PCL 5 (v5.0)', 'cJobs': 0, 'pSepFile': '', 'AveragePPM': 0, 'pPortName': 'IP_10.10.185.5', 'pParameters': '', 'pPrintProcessor': 'hpcpp091', 'Attributes': 8728, 'Priority': 1, 'pPrinterName': '\\\\cheops1\\4EPRINT1', 'DefaultPriority': 0, 'StartTime': 0, 'pDatatype': 'RAW', 'pDevMode': <PyDEVMODEA object at 0x01B92958>, 'pLocation': '10.10.185.5', 'pShareName': '4EPRINT1', 'pServerName': '\\\\cheops1', 'pSecurityDescriptor': <PySECURITY_DESCRIPTOR object at 0x01C74560>, 'pComment': 'Rm 4053, 4E Main Desk Laser, Laserjet 4100 MFP, LNWID - 711096'}
    Traceback (most recent call last):
        File "D:\workspace\Clinical Applications\EPIC\EPIC_Values.py", line 183, in <module>
            AddPrinter(computer, printer)
        File "D:\workspace\Clinical Applications\EPIC\EPIC_Values.py", line 161, in AddPrinter
            win32print.AddPrinter(computer, 2, pInfo)
    pywintypes.error: (1801, 'AddPrinter', 'The printer name is invalid.')
4

0 回答 0