c# - Preventing ComExceptions when querying via WMI -



c# - Preventing ComExceptions when querying via WMI -

i've got code uses wmi scour windows domain computers matching criteria.

i comexception if i'm unable communicate computer i'm trying query. when testing on big domain, can result in thousands of exceptions beingness thrown, expensive performance-wise.

is there way me check valid connection, before querying, can prevent these errors happening?

simplified example:

foreach(var computer in domain) { var scope = new managementscope(computerpath, options), query); seek { using (var searcher = new managementobjectsearcher(scope)) { if (searcher.get().count == 0) { // stuff } } } catch(comexception e) { // log , go on } }

this bit of code in vbscript (vbs) via wmi: initialize wmi connection, , perform error handling authentication or connection issues. imagine take 30 seconds knows both "transcribe" c#. :)

' verify computer exists , business relationship used has sufficient rights set objswbemservices = getobject( "winmgmts:\\" & strcomputer & "\root\cimv2" ) if( isempty( objswbemservices ) = true ) wscript.echo( "object_not_initialized :: " & strcomputer ) wscript.quit( object_not_initialized ) end if

c# wmi comexception

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -