PrintUIEntryW (printui)
Last changed: -194.78.68.20

.
Summary
PrintUIEntryW is the main entrypoint to the printer configuration functions in the PrintUI.dll.

Advantages of using the function directly in your program instead of calling rundll32.exe are meanful error codes and no external process needs to be called resulting in more control.

C# Signature:

[DllImport("printui.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern void PrintUIEntryW(IntPtr hwnd, IntPtr hinst, string lpszCmdLine, int nCmdShow);

VB.NET Signature:

<DllImport("printui", SetLastError:=True, CharSet:=CharSet.Unicode)> _
Public Shared Function PrintUIEntry(hwnd As IntPtr, hinst As IntPtr, lpszCmdLine As String, nCmdShow As Integer) As Boolean
End Function

Sample Code:

Get available commands in dialup box

PrintUIEntry(IntPtr.Zero, IntPtr.Zero, @"/?", 0);

Add per machine printer connection (the connection will be propagated to the user upon logon):

PrintUIEntry(IntPtr.Zero, IntPtr.Zero, @"/c \\machine /ga /n\\server\queue", 0);

Delete per machine printer connection (the connection will be deleted upon user logon):

PrintUIEntry(IntPtr.Zero, IntPtr.Zero, @"/c \\machine /gd /n\\server\queue", 0);

Install network printer:

PrintUIEntry(IntPtr.Zero, IntPtr.Zero, "/in /n\\server\printername", 0)

View default printer's properties

PrintDocument printDoc = new PrintDocument();

PrintUIEntryW(IntPtr.Zero, IntPtr.Zero, @"/p /n " + "\ " + printDoc.PrinterSettings.PrinterName + "\ ", 0);

// "\"" required for printer name with spaces

Documentation