Advertisement
linuxlizard

Win32 Python Open Printer

Mar 18th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1.     printer_dev_path = None
  2.     for port, desc, hwid in win32setupdi.printers(True):
  3.         print "port=%-10s:\n desc=%s\n hwid=(%s)" % (port, desc, hwid)
  4.  
  5.         if port.find( vid_path ) > 0 and port.find( pid_path ) > 0 :
  6.             printer_dev_path = port
  7.  
  8.     if printer_dev_path is None :
  9.         print "Printer not attached."
  10.         sys.exit(1)
  11.  
  12.     print "opening port={0}".format( printer_dev_path )
  13.     file_handle = win32file.CreateFile( printer_dev_path,
  14.                     win32con.GENERIC_READ | win32con.GENERIC_WRITE,
  15.                     0, # exclusive access
  16.                     None, # no security
  17.                     win32con.OPEN_EXISTING,
  18.                     win32con.FILE_ATTRIBUTE_NORMAL | win32con.FILE_FLAG_OVERLAPPED,
  19.                     None)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement