set default printer

C

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!
 
C

Crespo

δ´¦ÀíµÄ¡°System.Management.ManagementException¡±ÀàÐ͵ÄÒì³£
³öÏÖÔÚ system.management.dll ÖÐ

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


"Steven" <[email protected]> дÈëÏûÏ¢
What error is being thrown?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top