home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / ADSDK.ZIP / Samples / WinNT / PrintQueue / vb / PrintQueue.bas next >
Encoding:
BASIC Source File  |  1999-03-17  |  7.5 KB  |  314 lines

  1. Attribute VB_Name = "PrintQueue"
  2. '----------------------------------------------------------------------------
  3. '
  4. '  Microsoft Active Directory 2.5 Sample Code
  5. '
  6. '  Copyright (C) Microsoft Corporation, 1996 - 1999
  7. '
  8. '  File:       printqueue.bas
  9. '
  10. '  Contents:   Show how to enumerate and display print queue and print jobs
  11. '
  12. '----------------------------------------------------------------------------
  13.  
  14. '----- Print Status ------------------
  15. Public Const PRINTER_STATUS_PAUSED = &H1
  16. Public Const PRINTER_STATUS_ERROR = &H2
  17. Public Const PRINTER_STATUS_PENDING_DELETION = &H4
  18. Public Const PRINTER_STATUS_PAPER_JAM = &H8
  19. Public Const PRINTER_STATUS_PAPER_OUT = &H10
  20. Public Const PRINTER_STATUS_MANUAL_FEED = &H20
  21. Public Const PRINTER_STATUS_PAPER_PROBLEM = &H40
  22. Public Const PRINTER_STATUS_OFFLINE = &H80
  23. Public Const PRINTER_STATUS_IO_ACTIVE = &H100
  24. Public Const PRINTER_STATUS_BUSY = &H200
  25. Public Const PRINTER_STATUS_PRINTING = &H400
  26. Public Const PRINTER_STATUS_OUTPUT_BIN_FULL = &H800
  27. Public Const PRINTER_STATUS_NOT_AVAILABLE = &H1000
  28. Public Const PRINTER_STATUS_WAITING = &H2000
  29. Public Const PRINTER_STATUS_PROCESSING = &H4000
  30. Public Const PRINTER_STATUS_INITIALIZING = &H8000
  31. Public Const PRINTER_STATUS_WARMING_UP = &H10000
  32. Public Const PRINTER_STATUS_TONER_LOW = &H20000
  33. Public Const PRINTER_STATUS_NO_TONER = &H40000
  34. Public Const PRINTER_STATUS_PAGE_PUNT = &H80000
  35. Public Const PRINTER_STATUS_USER_INTERVENTION = &H100000
  36. Public Const PRINTER_STATUS_OUT_OF_MEMORY = &H200000
  37. Public Const PRINTER_STATUS_DOOR_OPEN = &H400000
  38. Public Const PRINTER_STATUS_SERVER_UNKNOWN = &H800000
  39. Public Const PRINTER_STATUS_POWER_SAVE = &H1000000
  40.  
  41.  
  42. Public Const JOB_STATUS_PAUSED = &H1
  43. Public Const JOB_STATUS_ERROR = &H2
  44. Public Const JOB_STATUS_DELETING = &H4
  45. Public Const JOB_STATUS_SPOOLING = &H8
  46. Public Const JOB_STATUS_PRINTING = &H10
  47. Public Const JOB_STATUS_OFFLINE = &H20
  48. Public Const JOB_STATUS_PAPEROUT = &H40
  49. Public Const JOB_STATUS_PRINTED = &H80
  50. Public Const JOB_STATUS_DELETED = &H100
  51. Public Const JOB_STATUS_BLOCKED_DEVQ = &H200
  52. Public Const JOB_STATUS_USER_INTERVENTION = &H400
  53. Public Const JOB_STATUS_RESTART = &H800
  54.  
  55.  
  56.  
  57.  
  58. Sub Main()
  59.  
  60.  
  61. Dim printQueue As IADsPrintQueue
  62. Dim printQOps As IADsPrintQueueOperations
  63. Dim printJob As IADsPrintJob
  64. Dim printJobOps As IADsPrintJobOperations
  65.  
  66.  
  67. computerName = "MSPRINT44"
  68. printQueueName = "CORPF"
  69.  
  70. Set comp = GetObject("WinNT://" & computerName & ",computer")
  71.  
  72. comp.Filter = Array("PrintQueue")
  73.  
  74. '----------------------------------------------------
  75. '--- Enumerating Printer in a computer -------------
  76. '----------------------------------------------------
  77.  
  78. For Each printQueue In comp
  79.  
  80.   s = printQueue.Name & " " & printQueue.Description & " (" & printQueue.PrinterPath & ")"
  81.   'Debug.Print printQueue.status
  82.   
  83.   '-- QI the PrintQueueOperations ( this is optional step in VB/VBScript )
  84.   Set printQOps = printQueue
  85.   s = s & "Status: " & GetPrintStatus(printQueue.status)
  86.   Debug.Print s  ' Report the printQueue and Printer status
  87. Next
  88.  
  89. '---------------------------------------------------
  90. '---- Binding to a specific printer queue ---------
  91. '---------------------------------------------------
  92. Set comp = GetObject("WinNT://" & computerName & ",computer")
  93. Set printQueue = comp.GetObject("PrintQueue", printQueueName)
  94.  
  95. '-- Get Print Queue Characteristics
  96. Debug.Print printQueue.Name & " " & printQueue.Description & " (" & printQueue.PrinterPath & ")"
  97. Debug.Print s
  98. '--- Swith to Print Queue Operation
  99. Set printQOps = printQueue
  100. Debug.Print "Status: " & GetPrintStatus(printQueue.status)
  101.  
  102.  
  103.  
  104. '---- Get Print Jobs for this specific queue --------------------
  105.  
  106.  
  107. Debug.Print "--- Jobs in the queue ----- "
  108. For Each printJob In printQOps.PrintJobs
  109.    Debug.Print printJob.Description & " " & printJob.User & " " & printJob.Priority
  110.    Set printJobOps = printJob
  111.    Debug.Print "Page printed: " & printJobOps.PagesPrinted & "Page(s) " & GetJobStatus(printJobOps.status)
  112.    Debug.Print "-----"
  113. Next
  114.  
  115.  
  116.  
  117.   
  118.  
  119.  
  120. End Sub
  121.  
  122.  
  123.  
  124. Function GetPrintStatus(status As Long) As String
  125.  
  126. s = ""
  127.  
  128. If (status = 0) Then
  129.   GetPrintStatus = "OK"
  130.   Exit Function
  131. End If
  132.  
  133.  
  134.  
  135. If (status And PRINTER_STATUS_PAUSED) Then
  136.   s = s + " Pause"
  137. End If
  138.  
  139. If (status And PRINTER_STATUS_PAUSED) Then
  140.   s = s + " Pause"
  141. End If
  142.  
  143. If (status And PRINTER_STATUS_ERROR) Then
  144.   s = s + " Error"
  145. End If
  146.  
  147. If (status And PRINTER_STATUS_PENDING_DELETION) Then
  148.   s = s + " Pending Deletion"
  149. End If
  150.  
  151.  
  152. If (status And PRINTER_STATUS_PENDING_DELETION) Then
  153.      s = s + " Pending Deletion"
  154. End If
  155.  
  156. If (status And PRINTER_STATUS_PAPER_JAM) Then
  157.      s = s + " Paper Jam"
  158. End If
  159.  
  160. If (status And PRINTER_STATUS_PAPER_OUT) Then
  161.      s = s + " Paper Out"
  162. End If
  163.  
  164. If (status And PRINTER_STATUS_MANUAL_FEED) Then
  165.      s = s + " Manual Feed"
  166. End If
  167.  
  168. If (status And PRINTER_STATUS_PAPER_PROBLEM) Then
  169.      s = s + " Paper Problem"
  170. End If
  171.  
  172. If (status And PRINTER_STATUS_OFFLINE) Then
  173.      s = s + " OffLine"
  174. End If
  175.  
  176. If (status And PRINTER_STATUS_IO_ACTIVE) Then
  177.      s = s + " IO Active"
  178. End If
  179.  
  180. If (status And PRINTER_STATUS_BUSY) Then
  181.      s = s + " Busy"
  182. End If
  183.  
  184. If (status And PRINTER_STATUS_PRINTING) Then
  185.      s = s + " Printing"
  186. End If
  187.  
  188. If (status And PRINTER_STATUS_OUTPUT_BIN_FULL) Then
  189.      s = s + " Output Bin Full"
  190. End If
  191.  
  192. If (status And PRINTER_STATUS_NOT_AVAILABLE) Then
  193.      s = s + " Not Available"
  194. End If
  195.  
  196. If (status And PRINTER_STATUS_WAITING) Then
  197.      s = s + " Waiting"
  198. End If
  199.  
  200. If (status And PRINTER_STATUS_PROCESSING) Then
  201.      s = s + " Processing"
  202. End If
  203.  
  204. If (status And PRINTER_STATUS_INITIALIZING) Then
  205.      s = s + " Initializing"
  206. End If
  207.  
  208.  
  209. If (status And PRINTER_STATUS_WARMING_UP) Then
  210.      s = s + " Warming up"
  211. End If
  212.  
  213. If (status And PRINTER_STATUS_TONER_LOW) Then
  214.      s = s + " Toner Low"
  215. End If
  216.  
  217. If (status And PRINTER_STATUS_NO_TONER) Then
  218.      s = s + " No Toner"
  219. End If
  220.  
  221. If (status And PRINTER_STATUS_PAGE_PUNT) Then
  222.      s = s + " Can print Current Page"
  223. End If
  224.  
  225. If (status And PRINTER_STATUS_USER_INTERVENTION) Then
  226.      s = s + " User Intervention"
  227. End If
  228.  
  229. If (status And PRINTER_STATUS_OUT_OF_MEMORY) Then
  230.      s = s + " Out of Memory"
  231. End If
  232.  
  233. If (status And PRINTER_STATUS_DOOR_OPEN) Then
  234.      s = s + " Door Open"
  235. End If
  236.  
  237. If (status And PRINTER_STATUS_SERVER_UNKNOWN) Then
  238.      s = s + " Server Unknown"
  239. End If
  240.  
  241. If (status And PRINTER_STATUS_POWER_SAVE) Then
  242.      s = s + " Power Save"
  243. End If
  244.  
  245. GetPrintStatus = s
  246.  
  247. End Function
  248.  
  249.  
  250.  
  251. Function GetJobStatus(status As Long) As String
  252.  
  253. s = ""
  254.  
  255. If (status = 0) Then
  256.   GetJobStatus = "OK"
  257.   Exit Function
  258. End If
  259.  
  260.  
  261. If (status And JOB_STATUS_PAUSED) Then
  262.   s = s + " Paused"
  263. End If
  264.  
  265. If (status And JOB_STATUS_ERROR) Then
  266.  s = s + " Error"
  267. End If
  268.  
  269. If (status And JOB_STATUS_DELETING) Then
  270.  s = s + " Deleting"
  271. End If
  272.  
  273. If (status And JOB_STATUS_SPOOLING) Then
  274.  s = s + " Spooling"
  275. End If
  276.  
  277. If (status And JOB_STATUS_PRINTING) Then
  278.  s = s + " Printing"
  279. End If
  280.  
  281. If (status And JOB_STATUS_OFFLINE) Then
  282.  s = s + " Offline"
  283. End If
  284.  
  285. If (status And JOB_STATUS_PAPEROUT) Then
  286.  s = s + " Paper Out"
  287. End If
  288.  
  289. If (status And JOB_STATUS_PRINTED) Then
  290.  s = s + " Printed"
  291. End If
  292.  
  293. If (status And JOB_STATUS_DELETED) Then
  294.  s = s + " Deleted"
  295. End If
  296.  
  297.  
  298. If (status And JOB_STATUS_BLOCKED_DEVQ) Then
  299.  s = s + " Blocked"
  300. End If
  301.  
  302. If (status And JOB_STATUS_USER_INTERVENTION) Then
  303.  s = s + " User Intervention"
  304. End If
  305.  
  306. If (status And JOB_STATUS_RESTART) Then
  307.  s = s + " Restart"
  308. End If
  309.  
  310.  
  311. GetJobStatus = s
  312. End Function
  313.  
  314.