c# - WMI printer.put() access denied -


i trying modify "keep printed jobs" property each printer using following code:

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.management;  namespace consoleprintpref { class program {     static void main(string[] args)     {         console.writeline("modify printer parameters");          managementscope scope = new managementscope("root\\cimv2");         scope.connect();          string searchquery = "select * win32_printer";         managementobjectsearcher searchprinters = new managementobjectsearcher(searchquery);         managementobjectcollection printercollection = searchprinters.get();          foreach (managementobject printer in printercollection)         {             propertydatacollection printerproperties = printer.properties;             foreach (propertydata property in printerproperties)             {                 if (property.name == "keepprintedjobs")                 {                     printerproperties[property.name].value = true;                 }             }             printer.put(); //access denied         }      }    } } 

but throws error: unhandled exception of type 'system.management.managementexception' occurred in system.management.dll additional information: access denied

i on administrator account, , in wmimgmt shows administrator has write permissions. there i'm missing somewhere?

try run visual studio administrator.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -