Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How To clean out Printer Spooler Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
clean out Printer Spooler 07-Jun-05
Category
Reporting /Printing
Language
Delphi All Versions
Views
380
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
Prasetya, sandy
Reference URL:
sandy prasetya
			1   
2   //this code shows how to clean out the printer spooler
3   uses WinSpool, Windows
4   
5   procedure ClearPrinterSpooler( iPrinterName : string );
6   const
7     Defaults: TPrinterDefaults = (
8       pDatatype : nil;
9       pDevMode : nil;
10      DesiredAccess : PRINTER_ACCESS_USE or PRINTER_ACCESS_ADMINISTER );
11  
12  var PrinterHandle : THandle;
13  
14    function GetJobCount: LongWord;
15    type
16      TPrinterInfos = array[0..0] of _PRINTER_INFO_2; //TPrinterInfo - Typecasting
17    var
18      vpPrintEnum : pointer;
19      vPI       : _PRINTER_INFO_2;
20      vHGlobal  : cardinal;
21      vLevel    : DWORD;
22      vNeeded   : DWORD;
23      vReturned : DWORD;
24      vFlag     : BOOLEAN;
25      vIdx      : dword;
26    begin
27      {$R-}
28      vpPrintEnum :=  nil;
29      vHGlobal := 0;
30      try
31        vLevel := 2;
32        result := 0;
33        EnumPrinters(PRINTER_ENUM_LOCAL, nil, vLevel, vpPrintEnum, 0, vNeeded,
34                     vReturned);
35        if (vNeeded = 0) then exit;
36  
37        // allocate memory
38        vHGlobal := GlobalAlloc(GHND, vNeeded);
39        vpPrintEnum := GlobalLock(vHGlobal);
40        if (vpPrintEnum = nil) then exit;
41  
42        vFlag := EnumPrinters(PRINTER_ENUM_LOCAL, PChar(iPrinterName), vLevel, 
43                 vpPrintEnum, vNeeded,
44                 vNeeded, vReturned);
45        if (not vFlag) then exit;
46  
47        for vIdx := 0 to vReturned-1 do
48        begin
49           vPI := TPrinterInfos(vpPrintEnum^)[vIdx];
50           if ( Uppercase( vPI.pPrinterName) = Uppercase( iPrinterName )  )then 
51           begin
52             result := vPI.cJobs;
53             break;
54           end;
55        end;
56      finally
57        if (vpPrintEnum <> nil) then GlobalUnlock(vHGlobal);
58        if (vHGlobal <> null) then GlobalFree(vHGlobal);
59      end;
60      {$R+}
61    end;
62  
63  begin
64    if not OpenPrinter(PChar( iPrinterName ), PrinterHandle, @Defaults) then
65      GetLastError;
66    try
67      //if spooler have job then clean it.
68      if GetJobCount > 0 then begin
69        if not WinSpool.SetPrinter( PrinterHandle, 0, nil, PRINTER_CONTROL_PURGE )
70        then
71          GetLastError;
72      end;    
73    finally
74      ClosePrinter( PrinterHandle );
75    end;
76  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC