Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if there is a default printer (Windows)?

Is there a API or registry key which I can use from applications (native, Java or .Net) to check if the currently logged on user has configured a default printer?

Update: Many thanks for the answers so far! According to the KB article http://support.microsoft.com/kb/156212, the registry entry (read/write) is only documented up to Windows 2000. Is there a Win API method in newer versions for native access?

like image 556
mjn Avatar asked Jan 21 '23 14:01

mjn


1 Answers

In .NET this code works for me:

public static string DefaultPrinterName()
{
  string functionReturnValue = null;
  System.Drawing.Printing.PrinterSettings oPS 
    = new System.Drawing.Printing.PrinterSettings();

  try
  {
    functionReturnValue = oPS.PrinterName;
  }
  catch (System.Exception ex)
  {
    functionReturnValue = "";
  }
  finally
  {
    oPS = null;
  }
  return functionReturnValue;
}

From: http://in.answers.yahoo.com/question/index?qid=20070920032312AAsSaPx

like image 135
Wojtek Turowicz Avatar answered Jan 28 '23 17:01

Wojtek Turowicz