我收到错误
pywintypes.error: (1801, 'AddPrinter', 'The printer name is invalid.')
我的目的是为最终用户计算机添加一台网络打印机...继续我的def
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.')