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
|
procedure TForm1.EmptySpooler;
var
SpoolFile: TSearchRec;
a : Integer;
begin
// On arrête le service Spooler d'impression
ShellExecute(0,nil,PChar('net'),PChar('stop spooler'),nil,SW_HIDE);
// On cherche dans le registre le répertoire du spool car il se peut que l'utilisateur l'ait changé.
with TRegistry.Create do try
RootKey := HKEY_LOCAL_MACHINE;
OpenKey('SYSTEM\CurrentControlSet\Control\Print\Printers', false);
// On supprime tous les fichiers en attente
a := FindFirst(IncludeTrailingPathDelimiter(ReadString('DefaultSpoolDirectory'))+'*.*', FaAnyfile, SpoolFile);
while a = 0 do begin
if ((SpoolFile.Attr and FaDirectory <> FaDirectory) and (SpoolFile.Attr and FaVolumeId <> FaVolumeID)) then
DeleteFile(pChar(IncludeTrailingPathDelimiter(ReadString('DefaultSpoolDirectory')) + SpoolFile.Name));
a := FindNext(SpoolFile);
end ;
SysUtils.FindClose(SpoolFile);
CloseKey;
Finally
Free;
end;
// On redémarre le service Spooler d'impression
ShellExecute(0,nil,PChar('net'),PChar('start spooler'),nil,SW_HIDE);
end; |
Partager