1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
| procedure TForm1.WM_SpoolerStatus(var Msg : TWMSPOOLERSTATUS);
begin
Label1.Caption := IntToStr(msg.JobsLeft) + ' Jobs currenly in spooler';
msg.Result := 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
const
MaxJobs = 1024;
type
TArrayofJobs = array[1..1024] of TJobInfo2;
var
NumJobs : integer;
pcbNeed,pcReturned:DWord;
i : integer;
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hPrinter: THandle;
hDeviceMode: THandle;
Buffer: Pointer;
TmpWinDir : array[0..255] of Char;
Windir : string;
Inputfile : textfile;
line : string;
// PNotifyName : PChar;
begin
if GetWindowsDirectory(TmpWinDir, sizeof(TmpWinDir)) <> 0 then
Windir := Strpas(TmpWinDir) + '\SPOOL\PRINTERS\'
else
Windir := 'C:\WINDOWS\SPOOL\PRINTERS\';
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
if not WinSpool.OpenPrinter(@Device, hPrinter, nil) then exit;
ListBox1.items.clear;
ListBox1.items.add('Windir :='+WinDir);
GetPrinter(hPrinter, 2, nil,0,@pcbNeed); // return false, Don't Care
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);
EnumJobs(hPrinter, 0, NumJobs, 2, nil, 0, pcbNeed, pcReturned);
GetMem(Buffer, pcbNeed);
if EnumJobs(hPrinter, 0, NumJobs, 2, Buffer, pcbNeed, pcbNeed,
pcReturned) then
begin
ListBox1.items.add('enumjobs ='+inttostr(pcReturned));
for i := 1 to pcReturned do
begin
ListBox1.items.add('===========Ѕлог с описанием файла===========');
ListBox1.items.add('JobId='+inttostr(TArrayofJobs(buffer^)[i].JobId));
if TarrayofJobs(buffer^)[i].pPrinterName <> nil then
ListBox1.items.add('pPrinterName='+TarrayofJobs(buffer^)[i].pPrinterName);
if TarrayofJobs(buffer^)[i].pMachineName <> nil then
ListBox1.items.add('pMachineName='+TarrayofJobs(buffer^)[i].pMachineName);
if TarrayofJobs(buffer^)[i].pUserName <> nil then
ListBox1.items.add('pUserName='+TarrayofJobs(buffer^)[i].pUserName);
if TarrayofJobs(buffer^)[i].pDocument <> nil then
ListBox1.items.add('pDocument='+TarrayofJobs(buffer^)[i].pDocument);
if TarrayofJobs(buffer^)[i].pDatatype <> nil then
ListBox1.items.add('pDatatype='+TarrayofJobs(buffer^)[i].pDatatype);
if TarrayofJobs(buffer^)[i].pStatus <> nil then
ListBox1.items.add('pStatus='+TarrayofJobs(buffer^)[i].pStatus);
if TarrayofJobs(buffer^)[i].pStatus <> nil then
ListBox1.items.add('pStatus='+TarrayofJobs(buffer^)[i].pStatus);
ListBox1.items.add('Size='+Inttostr(TarrayofJobs(buffer^)[i].Size));
ListBox1.items.add('Status='+Inttostr(TarrayofJobs(buffer^)[i].Status));
ListBox1.items.add('Priority='+Inttostr(TarrayofJobs(buffer^)[i].Priority));
ListBox1.items.add('Position='+Inttostr(TarrayofJobs(buffer^)[i].Position));
ListBox1.items.add('TotalPages='+Inttostr(TarrayofJobs(buffer^)[i].TotalPages));
ListBox1.items.add('PagesPrinted='+Inttostr(TarrayofJobs(buffer^)[i].PagesPrinted));
with TArrayofJobs(buffer^)[i].Submitted do
begin
ListBox1.items.add('Submited wYear='+Inttostr(wYear));
ListBox1.items.add('Submited wMonth='+Inttostr(wMonth));
ListBox1.items.add('Submited wDayOfWeek='+Inttostr(wDayOfWeek));
ListBox1.items.add('Submited wDay='+Inttostr(wDay));
ListBox1.items.add('Submited wHour='+Inttostr(wHour));
ListBox1.items.add('Submited wMinute='+Inttostr(wMinute));
ListBox1.items.add('Submited wMinute='+Inttostr(wSecond));
ListBox1.items.add('Submited wMilliseconds='+Inttostr(wMilliseconds));
end;
ListBox1.items.add(Windir +
format('%-0.5d.SPL',[TArrayofJobs(buffer^)[i].JobId]));
ListBox1.items.add('=======================================');
assignfile(inputfile,Windir +
format('*.SPL',[TArrayofJobs(buffer^)[i].JobId]));
reset(inputfile);
repeat
readln(inputfile,line);
ListBox1.items.add(line);
until eof(inputfile);
closefile(inputfile);
ListBox1.items.add('=======================================');
SetJob(hPrinter, TArrayofJobs(buffer^)[i].JobId, 0, nil,
JOB_CONTROL_CANCEL)
end;
end;
FreeMem(Buffer, pcbNeed);
WinSpool.ClosePrinter(hPrinter);
end;
end. |