Search code examples
asp.net.netwpfwmi

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


Solution

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