用代码删除打印机

function PE_DeletePrinterNow(pPrinterName: PChar):BOOL;
var hPrinter  : Cardinal; 
PrinterDef: PRINTER_DEFAULTS;

begin 
 Result := FALSE;
 FillChar(PrinterDef, sizeof(PrinterDef), #0);
 PrinterDef.DesiredAccess := PRINTER_ALL_ACCESS;
 if OpenPrinter(pPrinterName, hPrinter, @PrinterDef) then
     begin    
       if DeletePrinter(hPrinter) then Result := TRUE;
       ClosePrinter(hPrinter);  
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  PE_DeletePrinterNow(pchar('MyPrinter 1'));
end;

end.