Reputation: 994
I have followed this thread to make my application to connect to other machine but failed. The problems as I encountered is:
Netsh firewall set service RemoteAdmin
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
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
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