' List Printer Connections
' Windows Server 2003 : Yes
' Windows XP : Yes
' Windows 2000 : No
' Windows NT 4.0 : No
' Windows 98 : No
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
Wscript.Echo "Name: " & objPrinter.Name
Wscript.Echo "Is Default: " & objPrinter.Default
WScript.Echo "Status: " & objPrinter.PrinterStatus
Wscript.Echo "State: " & objPrinter.PrinterState
Next
Состояние принтера
После тщетных 3-х дневных поисков в сети, решил обратиться сюда.
Суть проблемы: нужно узнать текущее состояние LPT-принтера, операционка WinXP.
Программа всегда возвращает состояние ноль. Не пойму почему. Проблема наблюдается у многих программистов, но решение нигде не могу найти.
Решений много есть, но все выдают статус ноль, не зависимо от реального состояния принтера.
ПОМОГИТЕ !!!
Вот код:
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Printers, WinSpool, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
ListBox1: TListBox;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hPrinter: THandle;
hDeviceMode: THandle;
pcbNeed,pcReturned: DWORD;
Buffer: Pointer;
begin
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
if not OpenPrinter(@Device, hPrinter, nil) then Exit;
GetPrinter(hPrinter, 2, nil,0,@pcbNeed);
GetMem(Buffer, pcbNeed);
if GetPrinter(hPrinter, 2, Buffer, pcbNeed, @pcbNeed) then
begin
if TPrinterInfo2A(Buffer^).pServerName <> nil then
ListBox1.items.add('pServerName='+TPrinterInfo2A(Buffer^).pServerName);
if TPrinterInfo2A(Buffer^).pPrinterName <> nil then
ListBox1.items.add('pPrinterName='+TPrinterInfo2A(Buffer^).pPrinterName);
if TPrinterInfo2A(Buffer^).pShareName <> nil then
ListBox1.items.add('pShareName='+TPrinterInfo2A(Buffer^).pShareName);
if TPrinterInfo2A(Buffer^).pComment <> nil then
ListBox1.items.add('pComment='+TPrinterInfo2A(Buffer^).pComment);
if TPrinterInfo2A(Buffer^).pLocation <> nil then
ListBox1.items.add('pLocation='+TPrinterInfo2A(Buffer^).pLocation);
if TPrinterInfo2A(Buffer^).pPortName <> nil then
ListBox1.items.add('pPortName='+TPrinterInfo2A(Buffer^).pPortName);
if TPrinterInfo2A(Buffer^).pDriverName <> nil then
ListBox1.items.add('pDriverName='+TPrinterInfo2A(Buffer^).pDriverName);
if TPrinterInfo2A(Buffer^).pSepFile <> nil then
ListBox1.items.add('pSepFile='+TPrinterInfo2A(Buffer^).pSepFile);
if TPrinterInfo2A(Buffer^).pPrintProcessor <> nil then
ListBox1.items.add('pPrintProcessor='+TPrinterInfo2A(Buffer^).pPrintProcessor);
if TPrinterInfo2A(Buffer^).pDatatype <> nil then
ListBox1.items.add('pDatatype='+TPrinterInfo2A(Buffer^).pDatatype);
if TPrinterInfo2A(Buffer^).pParameters <> nil then
ListBox1.items.add('pParameters='+TPrinterInfo2A(Buffer^).pParameters);
ListBox1.items.add('Attributes='+inttostr(TPrinterInfo2A(Buffer^).Attributes));
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_QUEUED = PRINTER_ATTRIBUTE_QUEUED then
ListBox1.items.add(' PRINTER_ATTRIBUTE_QUEUED');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_QUEUED = PRINTER_ATTRIBUTE_QUEUED then
ListBox1.items.add(' PRINTER_ATTRIBUTE_QUEUED');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_DIRECT = PRINTER_ATTRIBUTE_DIRECT then
ListBox1.items.add(' PRINTER_ATTRIBUTE_DIRECT');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_DEFAULT = PRINTER_ATTRIBUTE_DEFAULT then
ListBox1.items.add(' PRINTER_ATTRIBUTE_DEFAULT');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_SHARED = PRINTER_ATTRIBUTE_SHARED then
ListBox1.items.add(' PRINTER_ATTRIBUTE_SHARED');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_NETWORK = PRINTER_ATTRIBUTE_NETWORK then
ListBox1.items.add(' PRINTER_ATTRIBUTE_NETWORK');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_HIDDEN = PRINTER_ATTRIBUTE_HIDDEN then
ListBox1.items.add(' PRINTER_ATTRIBUTE_HIDDEN');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_LOCAL = PRINTER_ATTRIBUTE_LOCAL then
ListBox1.items.add(' PRINTER_ATTRIBUTE_LOCAL');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_ENABLE_DEVQ = PRINTER_ATTRIBUTE_ENABLE_DEVQ then
ListBox1.items.add(' PRINTER_ATTRIBUTE_ENABLE_DEVQ');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS = PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS then
ListBox1.items.add(' PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST = PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST then
ListBox1.items.add('PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_WORK_OFFLINE = PRINTER_ATTRIBUTE_WORK_OFFLINE then
ListBox1.items.add(' PRINTER_ATTRIBUTE_WORK_OFFLINE');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_ENABLE_BIDI = PRINTER_ATTRIBUTE_ENABLE_BIDI then
ListBox1.items.add(' PRINTER_ATTRIBUTE_ENABLE_BIDI');
ListBox1.items.add('Priority='+inttostr(TPrinterInfo2A(Buffer^).Priority));
ListBox1.items.add('DefaultPriority='+inttostr(TPrinterInfo2A(Buffer^).DefaultPriority));
ListBox1.items.add('StartTime='+inttostr(TPrinterInfo2A(Buffer^).StartTime));
ListBox1.items.add('UntilTime='+inttostr(TPrinterInfo2A(Buffer^).UntilTime));
ListBox1.items.add('Status='+inttostr(TPrinterInfo2A(Buffer^).Status));
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PAUSED = PRINTER_STATUS_PAUSED then
ListBox1.items.add(' PRINTER_STATUS_PAUSED');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_ERROR = PRINTER_STATUS_ERROR then
ListBox1.items.add(' PRINTER_STATUS_ERROR');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PENDING_DELETION = PRINTER_STATUS_PENDING_DELETION then
ListBox1.items.add(' PRINTER_STATUS_PENDING_DELETION');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PAPER_JAM = PRINTER_STATUS_PAPER_JAM then
ListBox1.items.add(' PRINTER_STATUS_PAPER_JAM');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PAPER_OUT = PRINTER_STATUS_PAPER_OUT then
ListBox1.items.add(' PRINTER_STATUS_PAPER_OUT');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_MANUAL_FEED = PRINTER_STATUS_MANUAL_FEED then
ListBox1.items.add(' PRINTER_STATUS_MANUAL_FEED');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PAPER_PROBLEM = PRINTER_STATUS_PAPER_PROBLEM then
ListBox1.items.add(' PRINTER_STATUS_PAPER_PROBLEM');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_OFFLINE = PRINTER_STATUS_OFFLINE then
ListBox1.items.add(' PRINTER_STATUS_OFFLINE');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_IO_ACTIVE = PRINTER_STATUS_IO_ACTIVE then
ListBox1.items.add(' PRINTER_STATUS_IO_ACTIVE');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_BUSY = PRINTER_STATUS_BUSY then
ListBox1.items.add(' PRINTER_STATUS_BUSY');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PRINTING = PRINTER_STATUS_PRINTING then
ListBox1.items.add(' PRINTER_STATUS_PRINTING');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_OUTPUT_BIN_FULL = PRINTER_STATUS_OUTPUT_BIN_FULL then
ListBox1.items.add(' PRINTER_STATUS_OUTPUT_BIN_FULL');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_NOT_AVAILABLE = PRINTER_STATUS_NOT_AVAILABLE then
ListBox1.items.add(' PRINTER_STATUS_NOT_AVAILABLE');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_WAITING = PRINTER_STATUS_WAITING then
ListBox1.items.add(' PRINTER_STATUS_WAITING');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PROCESSING = PRINTER_STATUS_PROCESSING then
ListBox1.items.add(' PRINTER_STATUS_PROCESSING');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_INITIALIZING = PRINTER_STATUS_INITIALIZING then
ListBox1.items.add(' PRINTER_STATUS_INITIALIZING');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_WARMING_UP = PRINTER_STATUS_WARMING_UP then
ListBox1.items.add(' PRINTER_STATUS_WARMING_UP');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_TONER_LOW = PRINTER_STATUS_TONER_LOW then
ListBox1.items.add(' PRINTER_STATUS_TONER_LOW');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_NO_TONER = PRINTER_STATUS_NO_TONER then
ListBox1.items.add(' PRINTER_STATUS_NO_TONER');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PAGE_PUNT = PRINTER_STATUS_PAGE_PUNT then
ListBox1.items.add(' PRINTER_STATUS_PAGE_PUNT');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_USER_INTERVENTION = PRINTER_STATUS_USER_INTERVENTION then
ListBox1.items.add(' PRINTER_STATUS_USER_INTERVENTION');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_OUT_OF_MEMORY = PRINTER_STATUS_OUT_OF_MEMORY then
ListBox1.items.add(' PRINTER_STATUS_OUT_OF_MEMORY');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_DOOR_OPEN = PRINTER_STATUS_DOOR_OPEN then
ListBox1.items.add(' PRINTER_STATUS_DOOR_OPEN');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_SERVER_UNKNOWN = PRINTER_STATUS_SERVER_UNKNOWN then
ListBox1.items.add(' PRINTER_STATUS_SERVER_UNKNOWN');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_POWER_SAVE = PRINTER_STATUS_POWER_SAVE then
ListBox1.items.add(' PRINTER_STATUS_POWER_SAVE');
ListBox1.items.add('cJobs='+inttostr(TPrinterInfo2A(Buffer^).cJobs));
ListBox1.items.add('AveragePPM='+inttostr(TPrinterInfo2A(Buffer^).AveragePPM));
end;
FreeMem(Buffer, pcbNeed);
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Printers, WinSpool, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
ListBox1: TListBox;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hPrinter: THandle;
hDeviceMode: THandle;
pcbNeed,pcReturned: DWORD;
Buffer: Pointer;
begin
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
if not OpenPrinter(@Device, hPrinter, nil) then Exit;
GetPrinter(hPrinter, 2, nil,0,@pcbNeed);
GetMem(Buffer, pcbNeed);
if GetPrinter(hPrinter, 2, Buffer, pcbNeed, @pcbNeed) then
begin
if TPrinterInfo2A(Buffer^).pServerName <> nil then
ListBox1.items.add('pServerName='+TPrinterInfo2A(Buffer^).pServerName);
if TPrinterInfo2A(Buffer^).pPrinterName <> nil then
ListBox1.items.add('pPrinterName='+TPrinterInfo2A(Buffer^).pPrinterName);
if TPrinterInfo2A(Buffer^).pShareName <> nil then
ListBox1.items.add('pShareName='+TPrinterInfo2A(Buffer^).pShareName);
if TPrinterInfo2A(Buffer^).pComment <> nil then
ListBox1.items.add('pComment='+TPrinterInfo2A(Buffer^).pComment);
if TPrinterInfo2A(Buffer^).pLocation <> nil then
ListBox1.items.add('pLocation='+TPrinterInfo2A(Buffer^).pLocation);
if TPrinterInfo2A(Buffer^).pPortName <> nil then
ListBox1.items.add('pPortName='+TPrinterInfo2A(Buffer^).pPortName);
if TPrinterInfo2A(Buffer^).pDriverName <> nil then
ListBox1.items.add('pDriverName='+TPrinterInfo2A(Buffer^).pDriverName);
if TPrinterInfo2A(Buffer^).pSepFile <> nil then
ListBox1.items.add('pSepFile='+TPrinterInfo2A(Buffer^).pSepFile);
if TPrinterInfo2A(Buffer^).pPrintProcessor <> nil then
ListBox1.items.add('pPrintProcessor='+TPrinterInfo2A(Buffer^).pPrintProcessor);
if TPrinterInfo2A(Buffer^).pDatatype <> nil then
ListBox1.items.add('pDatatype='+TPrinterInfo2A(Buffer^).pDatatype);
if TPrinterInfo2A(Buffer^).pParameters <> nil then
ListBox1.items.add('pParameters='+TPrinterInfo2A(Buffer^).pParameters);
ListBox1.items.add('Attributes='+inttostr(TPrinterInfo2A(Buffer^).Attributes));
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_QUEUED = PRINTER_ATTRIBUTE_QUEUED then
ListBox1.items.add(' PRINTER_ATTRIBUTE_QUEUED');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_QUEUED = PRINTER_ATTRIBUTE_QUEUED then
ListBox1.items.add(' PRINTER_ATTRIBUTE_QUEUED');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_DIRECT = PRINTER_ATTRIBUTE_DIRECT then
ListBox1.items.add(' PRINTER_ATTRIBUTE_DIRECT');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_DEFAULT = PRINTER_ATTRIBUTE_DEFAULT then
ListBox1.items.add(' PRINTER_ATTRIBUTE_DEFAULT');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_SHARED = PRINTER_ATTRIBUTE_SHARED then
ListBox1.items.add(' PRINTER_ATTRIBUTE_SHARED');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_NETWORK = PRINTER_ATTRIBUTE_NETWORK then
ListBox1.items.add(' PRINTER_ATTRIBUTE_NETWORK');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_HIDDEN = PRINTER_ATTRIBUTE_HIDDEN then
ListBox1.items.add(' PRINTER_ATTRIBUTE_HIDDEN');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_LOCAL = PRINTER_ATTRIBUTE_LOCAL then
ListBox1.items.add(' PRINTER_ATTRIBUTE_LOCAL');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_ENABLE_DEVQ = PRINTER_ATTRIBUTE_ENABLE_DEVQ then
ListBox1.items.add(' PRINTER_ATTRIBUTE_ENABLE_DEVQ');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS = PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS then
ListBox1.items.add(' PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST = PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST then
ListBox1.items.add('PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_WORK_OFFLINE = PRINTER_ATTRIBUTE_WORK_OFFLINE then
ListBox1.items.add(' PRINTER_ATTRIBUTE_WORK_OFFLINE');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_ENABLE_BIDI = PRINTER_ATTRIBUTE_ENABLE_BIDI then
ListBox1.items.add(' PRINTER_ATTRIBUTE_ENABLE_BIDI');
ListBox1.items.add('Priority='+inttostr(TPrinterInfo2A(Buffer^).Priority));
ListBox1.items.add('DefaultPriority='+inttostr(TPrinterInfo2A(Buffer^).DefaultPriority));
ListBox1.items.add('StartTime='+inttostr(TPrinterInfo2A(Buffer^).StartTime));
ListBox1.items.add('UntilTime='+inttostr(TPrinterInfo2A(Buffer^).UntilTime));
ListBox1.items.add('Status='+inttostr(TPrinterInfo2A(Buffer^).Status));
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PAUSED = PRINTER_STATUS_PAUSED then
ListBox1.items.add(' PRINTER_STATUS_PAUSED');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_ERROR = PRINTER_STATUS_ERROR then
ListBox1.items.add(' PRINTER_STATUS_ERROR');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PENDING_DELETION = PRINTER_STATUS_PENDING_DELETION then
ListBox1.items.add(' PRINTER_STATUS_PENDING_DELETION');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PAPER_JAM = PRINTER_STATUS_PAPER_JAM then
ListBox1.items.add(' PRINTER_STATUS_PAPER_JAM');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PAPER_OUT = PRINTER_STATUS_PAPER_OUT then
ListBox1.items.add(' PRINTER_STATUS_PAPER_OUT');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_MANUAL_FEED = PRINTER_STATUS_MANUAL_FEED then
ListBox1.items.add(' PRINTER_STATUS_MANUAL_FEED');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PAPER_PROBLEM = PRINTER_STATUS_PAPER_PROBLEM then
ListBox1.items.add(' PRINTER_STATUS_PAPER_PROBLEM');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_OFFLINE = PRINTER_STATUS_OFFLINE then
ListBox1.items.add(' PRINTER_STATUS_OFFLINE');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_IO_ACTIVE = PRINTER_STATUS_IO_ACTIVE then
ListBox1.items.add(' PRINTER_STATUS_IO_ACTIVE');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_BUSY = PRINTER_STATUS_BUSY then
ListBox1.items.add(' PRINTER_STATUS_BUSY');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PRINTING = PRINTER_STATUS_PRINTING then
ListBox1.items.add(' PRINTER_STATUS_PRINTING');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_OUTPUT_BIN_FULL = PRINTER_STATUS_OUTPUT_BIN_FULL then
ListBox1.items.add(' PRINTER_STATUS_OUTPUT_BIN_FULL');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_NOT_AVAILABLE = PRINTER_STATUS_NOT_AVAILABLE then
ListBox1.items.add(' PRINTER_STATUS_NOT_AVAILABLE');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_WAITING = PRINTER_STATUS_WAITING then
ListBox1.items.add(' PRINTER_STATUS_WAITING');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PROCESSING = PRINTER_STATUS_PROCESSING then
ListBox1.items.add(' PRINTER_STATUS_PROCESSING');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_INITIALIZING = PRINTER_STATUS_INITIALIZING then
ListBox1.items.add(' PRINTER_STATUS_INITIALIZING');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_WARMING_UP = PRINTER_STATUS_WARMING_UP then
ListBox1.items.add(' PRINTER_STATUS_WARMING_UP');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_TONER_LOW = PRINTER_STATUS_TONER_LOW then
ListBox1.items.add(' PRINTER_STATUS_TONER_LOW');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_NO_TONER = PRINTER_STATUS_NO_TONER then
ListBox1.items.add(' PRINTER_STATUS_NO_TONER');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PAGE_PUNT = PRINTER_STATUS_PAGE_PUNT then
ListBox1.items.add(' PRINTER_STATUS_PAGE_PUNT');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_USER_INTERVENTION = PRINTER_STATUS_USER_INTERVENTION then
ListBox1.items.add(' PRINTER_STATUS_USER_INTERVENTION');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_OUT_OF_MEMORY = PRINTER_STATUS_OUT_OF_MEMORY then
ListBox1.items.add(' PRINTER_STATUS_OUT_OF_MEMORY');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_DOOR_OPEN = PRINTER_STATUS_DOOR_OPEN then
ListBox1.items.add(' PRINTER_STATUS_DOOR_OPEN');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_SERVER_UNKNOWN = PRINTER_STATUS_SERVER_UNKNOWN then
ListBox1.items.add(' PRINTER_STATUS_SERVER_UNKNOWN');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_POWER_SAVE = PRINTER_STATUS_POWER_SAVE then
ListBox1.items.add(' PRINTER_STATUS_POWER_SAVE');
ListBox1.items.add('cJobs='+inttostr(TPrinterInfo2A(Buffer^).cJobs));
ListBox1.items.add('AveragePPM='+inttostr(TPrinterInfo2A(Buffer^).AveragePPM));
end;
FreeMem(Buffer, pcbNeed);
end;
end.
Неужели никто не поможет?((
Что такое "состояние ноль", и где собственно оно возвращается? Из портянки не совсем понятно где проблема... GetPrinter? OpenPrinter? Где?
Код:
ListBox1.items.add('Status='+inttostr(TPrinterInfo2A(Buffer^).Status));
тут в листбоксе всегда "Status=0"
И далее все ифы "конец бумаги", "пауза", "идет печать", "ожидание" и т.д игногрируются. Тоесть просто в листбоксе не выводится текущая ошибка.
Извините если непонятно выражаюсь.
Порт небось надо правильно сконфигурировать. В биосе.
Phodopus, а можно поподробнее?
Через него можно получить информацию о любом компоненте системы, пример для принтеров на vbs выглядит так
Код:
Здесь вас интересуют свойства Status и State
Код:
Property PrinterState As uint32 (read-only)
Это свойство было опротестовано в пользу свойств PrinterStatus, DetectedErrorState и ErrorInformation CIM, которые более ясно указывают состояние и ошибки принтера. Свойство PrinterState указывает значение, определяющее одно из возможных состояний принтера.
Property PrinterStatus As uint16 (read-only)
Информация о состоянии принтера, помимо информации, представленной в свойстве Availability. Примеры допустимых значений: "Простаивание" (3), "Печать" (4).
Это свойство было опротестовано в пользу свойств PrinterStatus, DetectedErrorState и ErrorInformation CIM, которые более ясно указывают состояние и ошибки принтера. Свойство PrinterState указывает значение, определяющее одно из возможных состояний принтера.
Property PrinterStatus As uint16 (read-only)
Информация о состоянии принтера, помимо информации, представленной в свойстве Availability. Примеры допустимых значений: "Простаивание" (3), "Печать" (4).
У объекта objPrinter есть еще куча свойств и методов, их можно посмотреть на msdn или в гугле набрав Win32_Printer properties
Там же (в гугле) Вы найдете как обратиться к WMI из Делфи, это не сложно!
P.S. Возможно в Вашем коде нужно обращаться к свойству PrinterStatus вместо Status `inttostr(TPrinterInfo2A(Buffer^).Status)`
Успехов!
Цитата: Coryphaeus
Phodopus, а можно поподробнее?
Можно. Про режимы почитайте, возможно это ваш случай.