c# - WMI .NET Invalid query -
i keep getting "invalid query" exception when trying execute following query:
managementobjectsearcher searcher = new managementobjectsearcher("select * win32_diskquota quotavolume.deviceid = 'c:'"); managementobjectcollection quotacollection = searcher.get();
however works: "select * win32_diskquota".
according msdn:
for uses of class descriptors in clause, wmi flags query invalid , returns error. however, use dot (.) operator properties of type object in wmi. example, following query valid if prop valid property of myclass , type object:
select * myclass prop.embedprop = 5
does mean works if prop declared object?
here exception details:
system.management.managementexception unhandled hresult=-2146233087 message=invalid query source=system.management stacktrace: в system.management.managementexception.throwwithextendedinfo(managementstatus errorcode) в system.management.managementobjectcollection.managementobjectenumerator.movenext() в userquota.program.getquota() в c:\users\administrator\documents\visual studio 2015\projects\userquota\userquota\program.cs:строка 40 в userquota.program.main(string[] args) в c:\users\administrator\documents\visual studio 2015\projects\userquota\userquota\program.cs:строка 33 в system.appdomain._nexecuteassembly(runtimeassembly assembly, string[] args) в system.appdomain.executeassembly(string assemblyfile, evidence assemblysecurity, string[] args) в microsoft.visualstudio.hostingprocess.hostproc.runusersassembly() в system.threading.threadhelper.threadstart_context(object state) в system.threading.executioncontext.runinternal(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx) в system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx) в system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state) в system.threading.threadhelper.threadstart() innerexception:
yes. according win32_diskquota class documentation, quotavolume property reference win32_logicaldisk wmi class. quotation msdn supplied gave reason why query invalid according wql specs.
instead, can use this:
managementobjectsearcher searcher = new managementobjectsearcher("select * win32_diskquota quotavolume = \"win32_logicaldisk.deviceid=\\\"c:\\\"\""); managementobjectcollection quotacollection = searcher.get();
(notice escaping...)
Comments
Post a Comment