Guru's, what is wrong with this code please?

  • Thread starter Thread starter trint
  • Start date Start date
T

trint

Here is the error:
An unhandled exception of type 'System.Management.ManagementException'
occurred in system.management.dll
Additional information: Not found

here is the code:

string printerName = "";
foreach (ManagementObject printer in searcher.Get())
{
printerName = printer["Name"].ToString().ToLower();
if (printerName.Equals(@"\\web1\shipping1"))
{
//Console.WriteLine("Printer = " + printer["Name"]);
error occurs here>>> if
(printer["WorkOffline"].ToString().ToLower().Equals("true"))
{

//Class1.printerStatus = printer;
// printer is offline by user
// Console.WriteLine("Your Plug-N-Play printer is not
connected.");
}
else
{
// printer is not offline
// Console.WriteLine("Your Plug-N-Play printer is connected.");
}
}
}
 
Here is the error:
An unhandled exception of type
'System.Management.ManagementException' occurred in
system.management.dll Additional information: Not found

here is the code:

string printerName = "";
foreach (ManagementObject printer in searcher.Get())
{
printerName = printer["Name"].ToString().ToLower();
if (printerName.Equals(@"\\web1\shipping1"))
{
//Console.WriteLine("Printer = " + printer["Name"]);
error occurs here>>> if
(printer["WorkOffline"].ToString().ToLower().Equals("true"))
{

//Class1.printerStatus = printer;
// printer is offline by user
// Console.WriteLine("Your
Plug-N-Play printer is not connected.");
}
else
{
// printer is not offline
// Console.WriteLine("Your
Plug-N-Play printer is connected."); }
}
}

Trint,

Catch the ManagementException and examine the exception instance
to get more info.

Look here for an example:

http://msdn.microsoft.com/library/d...emmanagementmanagementexceptionclasstopic.asp

or

http://tinyurl.com/6m8ej
 
Should be:

if(bool)printer.Properties["WorkOffLine"].Value = true)
....
else
 
Willy Denoyette said:
Should be:

if(bool)printer.Properties["WorkOffLine"].Value = true)
...
else

<Pedant mode on>

if( (bool)printer.Properties["WorkOffLine"].Value == true)


Extra opening brace. 2 'equals'

<Pedant mode off>
 
Back
Top