VB.Net - Local WMI Connection with user credentials

扶醉桌前 提交于 2019-12-05 08:12:21

问题


In VB.Net, I'm trying to connect to WMI on my local computer with different credentials (the user won't have admin rights) and I get this exception :

« User credentials cannot be used for local connections »

Here's the code :

    Dim path As ManagementPath = Nothing
    Dim options As ConnectionOptions = Nothing
    Dim scope As ManagementScope = Nothing

    path = New ManagementPath("\\" & vServerName & "\root\CIMV2")

    options = New ConnectionOptions
    options.Username = vUsername
    options.Password = vPassword

    Scope = New ManagementScope(path, options)

    Scope.Connect()

回答1:


You don't have access to some wmi instances when a user without administrator privileges is currently logged in. (This is only applied to Local WMI connections)

MSDN reference on the topic

It's pretty lame! But if you can run your application as a user which is a member of administrators group, then you're problem should be solved.

Added note:

If you write a windows service with **local system** user, then you'll have full access to all wmi classes.


note: I've tried to grant my limited user the proper permissions to access desired wmi actions, but it seems it doesn't work that way. In this case, you'll have to set the permissions in these 3 places:

  1. Start->Run->dcmoncnfg->Component Services->Computers->My Computer->Properties->COM security tab
  2. Start->Run->dcmoncnfg->Component Services->Computers->My Computer->DCOM Config->Windows Management and Instrumention->Properties->Security tab
  3. Start->Run->wmimgmt.msc->WMI Control(Local)->Properties->Root(just highlight)->Security tab



回答2:


I know this question is old, but I tried the above steps and it didn't work. What I found to work was this:

https://web.archive.org/web/20150213044821/http://www.manageengine.com/network-monitoring/help/troubleshoot_opmanager/troubleshoot_wmi.html

80041064 - User credentials cannot be used for local connections

Cause

This error is encountered when you specify the Username and password for monitoring the machine where OpManager is running.

Solution

Do not specify Username and password for the localhost. To resolve the issue, remove the configured user name and password from "Passwords" link in the device snapshot page.




回答3:


enter the wmic prompt by typing wmic and then enter. Then type:

/user:""

This will null the user it's trying to run the commands as. You might have to do something similar with password, I dunno.



来源:https://stackoverflow.com/questions/8218763/vb-net-local-wmi-connection-with-user-credentials

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!