Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

DeletePrinter (winspool)
 
.
Summary
DeletePrinterConnection - disconnect / remove client connection to a shared printer
Summary
The DeletePrinter function deletes the specified printer object.

C# Signature:

[DllImport("winspool.drv", CharSet = CharSet.Ansi, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool DeletePrinterConnection(String pName);
[DllImport("winspool.drv", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
    static extern bool DeletePrinter(IntPtr hPrinter);

VB Signature:

Declare Function DeletePrinterConnection Lib "winspool.dll" (TODO) As TODO
Declare Function DeletePrinter Lib "winspool.dll" (TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Please add some!

Alternative using unmanaged printui.PrintUIEntryW

Sample Code:

bool result;

Int32 Win32Error;

result = DeletePrinterConnection("\\\\Server_Name\\Printer_Share");

if (result == false)

{

   Win32Error = Marshal.GetLastWin32Error();
   //Do something with Win32Error

}

Sample Code:

private void UninstallPrinter(String printerName)

    {
        IntPtr hPrinter;
        PRINTER_DEFAULTS defaults = new PRINTER_DEFAULTS
        {
        //PRINTER_ALL_ACCESS
        DesiredAccess = 0x000F000C,
        pDatatype = IntPtr.Zero,
        pDevMode = IntPtr.Zero
        };

Documentation

        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);
        }
    }

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions