I use WMI, I need to get some information, but when the class is unavailable due to insufficient permissions, everything freezes for several (~ 5) seconds. Even setting a low timeout does not work (not to mention that it would be a stupid solution).
The problem is not in insufficient permissions, the problem is "freezing".
Is there a way to check if the current process has the right to read information from any class in order to prevent the exception “freezing” and “denied access”?
ConnectionOptions co = new ConnectionOptions();
co.Impersonation = ImpersonationLevel.Impersonate;
co.Authentication = AuthenticationLevel.Packet;
co.Timeout = new TimeSpan(0, 0, 1);
co.EnablePrivileges = false;
ManagementPath mp = new ManagementPath();
mp.NamespacePath = @"root\CIMV2\Security\MicrosoftTpm";
mp.Server = "";
ManagementScope ms = new ManagementScope(mp, co);
ms.Connect();
source
share