-1

I´m getting Invalid Query error when trying to get locally installed remote printer info from Win32_Printer.

string query = "SELECT * from Win32_Printer WHERE Name = '\\\\Server\\PrinterName'";

ManagementScope scope = new ManagementScope(ManagementPath.DefaultPath);
SelectQuery objQuery = new SelectQuery(query);
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, objQuery))
using (ManagementObjectCollection coll = searcher.Get())
{
   foreach (ManagementObject printer in coll)
   {
      foreach (PropertyData property in printer.Properties)
         {
            result.Add(property.Name, property.Value);
         }
    }
}

I'm getting the name '\\\\Server\\PrinterName' from System.Drawing.Printing.PrinterSettings.InstalledPrinters.

If I change the query to

"SELECT * from Win32_Printer WHERE Name LIKE '%PrinterName'"

it works but how can I query on the full name?

user995219
  • 104
  • 11

1 Answers1

0

As comment from @JeroenMostert, the '\' character is an escape character in both c# and wmi so the solution is to double them.

user995219
  • 104
  • 11