Home All Groups Group Topic Archive Search About

set default printer

Author
12 May 2006 12:16 AM
Crespo
Hi,
  I have a problem to set default printer programatically using c#. My codes
works well in windows2003,but it fails in windows2000.
My codes is just listed below:

     System.Management.ManagementObjectSearcher query;
     ManagementObjectCollection queryCollection;
    string classname = "SELECT * FROM Win32_Printer";
    query = new ManagementObjectSearcher(classname);
    if (oldPrinter != myPrinter)
    {
      queryCollection = query.Get();
      foreach (ManagementObject mo in queryCollection)
     {
       if (string.Compare(mo["Name"].ToString(), myPrinter, true) == 0)
       {
         mo.InvokeMethod("SetDefaultPrinter", null);
         break;
        }
      }
   }

Can anyone help me? Thank you in advance!

Author
12 May 2006 2:01 AM
Steven
What error is being thrown?

Show quote
"Crespo" wrote:

> Hi,
>   I have a problem to set default printer programatically using c#. My codes
> works well in windows2003,but it fails in windows2000.
> My codes is just listed below:
>
>      System.Management.ManagementObjectSearcher query;
>      ManagementObjectCollection queryCollection;
>     string classname = "SELECT * FROM Win32_Printer";
>     query = new ManagementObjectSearcher(classname);
>     if (oldPrinter != myPrinter)
>     {
>       queryCollection = query.Get();
>       foreach (ManagementObject mo in queryCollection)
>      {
>        if (string.Compare(mo["Name"].ToString(), myPrinter, true) == 0)
>        {
>          mo.InvokeMethod("SetDefaultPrinter", null);
>          break;
>         }
>       }
>    }
>
> Can anyone help me? Thank you in advance!
>
>
>
Author
12 May 2006 3:34 PM
Crespo
δ´¦ÀíµÄ¡°System.Management.ManagementException¡±ÀàÐ͵ÄÒì³£
³öÏÖÔÚ system.management.dll ÖÐ

ÆäËûÐÅÏ¢£ºÃ»ÓÐÈκÎÀà±ðÖÐÖ´ÐÐÕâ¸ö·½·¨
Crespo


"Steven" <StevenSw@community.nospam> дÈëÏûÏ¢
news:D6E50C22-D1A4-4F50-809B-5C82655DEF56@microsoft.com...
What error is being thrown?

Show quote
"Crespo" wrote:

> Hi,
>   I have a problem to set default printer programatically using c#. My
codes
> works well in windows2003,but it fails in windows2000.
> My codes is just listed below:
>
>      System.Management.ManagementObjectSearcher query;
>      ManagementObjectCollection queryCollection;
>     string classname = "SELECT * FROM Win32_Printer";
>     query = new ManagementObjectSearcher(classname);
>     if (oldPrinter != myPrinter)
>     {
>       queryCollection = query.Get();
>       foreach (ManagementObject mo in queryCollection)
>      {
>        if (string.Compare(mo["Name"].ToString(), myPrinter, true) == 0)
>        {
>          mo.InvokeMethod("SetDefaultPrinter", null);
>          break;
>         }
>       }
>    }
>
> Can anyone help me? Thank you in advance!
>
>
>

AddThis Social Bookmark Button