manaclan
manaclan

Reputation: 994

WPF ManagementScope Access denied

I have followed this thread to make my application to connect to other machine but failed. The problems as I encountered is:

  1. "RPC Server Unavailable". I fixed it after using: Netsh firewall set service RemoteAdmin
  2. Then I got "Access denied". While trying to fix this, I found out my Remote Desktop Control (RDC) got connection error too, but I managed to fix that RDC by goto "System properties -> Allow remote connections to this computer" Here the demo

Here is my simplified code:

ConnectionOptions options = new ConnectionOptions();
options.Username = userName;
options.Password = password;
scope = new ManagementScope(string.Format("\\\\{0}\\root\\cimv2", computerName), options);
scope.Connect();

Updated 1 I ran WMI diag tool as @Rox suggested in the comment and these are the logs files generated.
Updated 2
I found out my error code (HResult) is -2146233087 but such error code doesn't exist on google

Upvotes: 0

Views: 683

Answers (2)

manaclan
manaclan

Reputation: 994

I make it work by importing Local Security Policy of a computer that my code can connect. Here is my config that works

Upvotes: 1

RoXTar
RoXTar

Reputation: 172

Try this for your options:

ConnectionOptions connOptions = new ConnectionOptions(); 
connOptions.Username = userName; 
connOptions.Password = password;
connOptions.Impersonation = ImpersonationLevel.Impersonate; 
connOptions.Authentication = AuthenticationLevel.PacketPrivacy; 
connOptions.EnablePrivileges = true;

Edit
For connections to local machine you don't have to use username and password, but you have to start app with sufficient rights

Best regards

Upvotes: 1

Related Questions