I was trying to access WMI information from a service and kept on getting errors

System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

I then went duh, the service account that it is running under wouldn’t have access to the network.

I suppose you could change the account on the service itself, but for a quick fix I changed

With WMIConnectionOptions

.Impersonation = System.Management.ImpersonationLevel.Impersonate
.Authentication = System.Management.AuthenticationLevel.Packet

End With

To:

With WMIConnectionOptions

.username = “my username”

.Password = “my password”

.Impersonation = System.Management.ImpersonationLevel.Impersonate
.Authentication = System.Management.AuthenticationLevel.Packet

End With

And that did the trick

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s