.net - WMI query in VB.NET - access denied -


i getting access denied when running below code alternate credentials ('access denied (exception hresult: 0x80070005 (e_accessdenied)).

if run whole program under standard credentials, pass administrator username & password wmi connection options, access denied. if right-click on program , choose "runas" , put in administrator username & password (without passing credentials wmi options) works! gather account has required privileges , required ports open don't believe dcom issue.

i have tried wbemtest program , can connect remote pc entering username , password. can connect no matter options choose impersonation & authentication level. in program, have experimented putting various parameters these options (see commented lines) , have tried .enableprivileges option no combination of these make program work. missing here?

    sub main()     dim myconnectionoptions new system.management.connectionoptions     myconnectionoptions         '.enableprivileges = true         '.impersonation = system.management.impersonationlevel.impersonate         '.authentication = system.management.authenticationlevel.packetprivacy         if textboxusername.text <> ""             .username = textboxusername.text             .password = textboxpassword.text         end if     end     'establish connection     try         dim mymanagementscope system.management.managementscope         mymanagementscope = new system.management.managementscope( _             "\\" & textboxcomputername.text & "\root\cimv2", myconnectionoptions)         'connect wmi namespace         mymanagementscope.connect()         dim myobjectsearcher new managementobjectsearcher( _             mymanagementscope.path.tostring, "select * win32_computersystem")         dim mycollection managementobjectcollection         dim myobject managementobject         'execute query         mycollection = myobjectsearcher.get()         each myobject in mycollection             if myobject.getpropertyvalue("username") nothing                 msgbox("ctrl-alt-del")             else                 msgbox(myobject.getpropertyvalue("username").tostring)             end if         next     catch e exception         msgbox("_connection error" & e.message)     end try end sub 

i assume wmi configuration correct in remote pc

in code need pass "mymanagementscope" object , create query object , pass both object searcher.

the below code in code didn't pass credentials ojectsearcher, change below code

    dim myobjectsearcher new managementobjectsearcher( _         mymanagementscope.path.tostring, "select * win32_computersystem") 

to

    dim x objectquery     x = new objectquery("select * win32_computersystem")      dim myobjectsearcher new managementobjectsearcher( _         mymanagementscope, x) 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -