The GetDefaultPrinter function retrieves the printer name of the default printer for the current user on the local computer
[DllImport("winspool.drv", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool GetDefaultPrinter(StringBuilder pszBuffer, ref int size);
Declare Function GetDefaultPrinter Lib "winspool.dll" (TODO) As TODO
None.
Works even if print spooler service is stopped (W2K)
StringBuilder dp = new StringBuilder(256);
int size = dp.Capacity;
if (GetDefaultPrinter(dp, ref size)) {
Console.WriteLine(String.Format("Printer: {0}, name length {1}", dp.ToString().Trim(), size));
} else {
int rc = GetLastError();
Console.WriteLine(String.Format("Failed. Size: {0}, error: {1:X}", size, rc));
}
Do you know one? Please contribute it!