I am trying to update some information about some printers on a remote server. I need to update things like location, comment and port. I have a solution that works, but I find it very slow, and I was wondering if anyone had an idea of why.
I get the printer (and later the port) from the server through WMI with this code: (this is the test code)
var test = DateTime.Now;
ManagementScope scope3 = new ManagementScope("\\\\printserver\\root\\cimv2");
scope3.Connect();
SelectQuery q3 = new SelectQuery("select * from Win32_Printer WHERE Name = 'printername'");
ManagementObjectSearcher search3 = new ManagementObjectSearcher(scope3, q3);
var printers3 = search3.Get();
foreach(var p in printers3)
{
}
var test2 = DateTime.Now.Subtract(test).TotalSeconds;
When this is done, test2 will contain the seconds "33.something". If I do this without the where clause, it will take almost the same time. Admittedly, there are almost 1,500 printers running on this server, but it seems to me that I can request one specific printer faster, and I don’t understand why the request with the where clause on the printer name takes the same time as the “select all” request.
Any suggestions?
-
Update
As shown below, I tried to execute the same query several times. However, it takes the same amount of time. It just seems strange to me that Windows should “touch” every printer on the system when I search for a specific one.
source
share