I want to remove a mapped printer and P/Invoking the following
[DllImport("winspool.drv", EntryPoint = "DeletePrinterConnection", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int DeletePrinterConnection(string pName);
When I use just the printer name or (PrinterName on server) I keep getting the printer name is invalid.
What name is this expecting as input?
Update 1
[DllImport("winspool.drv", EntryPoint = "DeletePrinterConnection")]
private static extern int DeletePrinterConnectionA(string pName);
DeletePrinterConnectionW (Unicode) and DeletePrinterConnectionA (ANSI)
int r = DeletePrinterConnectionA(printer);
if (!r.Equals(0))
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
This throws back Operation completed successfully - but it didn't and the printer is still there.
Return value
If the function succeeds, the return value is a nonzero value. If the function fails, the return value is zero.