[DllImport("winspool.drv", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
static extern bool DeletePrinter(IntPtr hPrinter);
Declare Function DeletePrinter Lib "winspool.dll" (TODO) As TODO
None.
Do you know one? Please contribute it!
None.
Alternative using unmanaged printui.PrintUIEntryW
private void UninstallPrinter(String printerName)
{
IntPtr hPrinter;
PRINTER_DEFAULTS defaults = new PRINTER_DEFAULTS
{
//PRINTER_ALL_ACCESS
DesiredAccess = 0x000F000C,
pDatatype = IntPtr.Zero,
pDevMode = IntPtr.Zero
};
if (OpenPrinter(printerName, out hPrinter, ref defaults) == false)
{
int errno = Marshal.GetLastWin32Error();
throw new Win32Exception(errno);
}
if (hPrinter == IntPtr.Zero)
{
int errno = Marshal.GetLastWin32Error();
throw new Win32Exception(errno);
}
if (DeletePrinter(hPrinter) == false)
{
int errno = Marshal.GetLastWin32Error();
throw new Win32Exception(errno);
}
if (ClosePrinter(hPrinter) == false)
{
int errno = Marshal.GetLastWin32Error();
throw new Win32Exception(errno);
}
}