Mitchel
Mitchel

Reputation: 59

VB.Net - Local WMI Connection with user credentials

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()

Upvotes: 2

Views: 20132

Answers (3)

Garrett
Garrett

Reputation: 1

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.

Upvotes: 0

Robert
Robert

Reputation: 1726

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.

Upvotes: 5

Bizhan
Bizhan

Reputation: 17125

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

Upvotes: 4

Related Questions