首页 > 解决方案 > 对 Win32_DiskDrive 类使用非管理员用户时,WMI 会出现一般故障

问题描述

我已为非管理员帐户提供了适当的权限,并且用户已添加到“分布式 COM 用户”组中。

尝试访问Win32_DiskDriveWin32_DiskDriveToDiskPartition上课时,Generic Failure出现错误。是否需要任何额外的许可?

标签: wmi

解决方案


您应该添加正确的权限

       ConnectionOptions connOptions = new ConnectionOptions();
       connOptions.Impersonation = ImpersonationLevel.Impersonate;
       //Add AuthenticationLevel that suits your need
       connOptions.Authentication = AuthenticationLevel.PacketPrivacy; 
       connOptions.EnablePrivileges = true;

       ManagementScope scope =
  new ManagementScope("MANAGEMNET_PATH"
, connOptions);
       scope.Connect();


       ObjectQuery query = new ObjectQuery(
           "YOUR QUERY");
       ManagementObjectSearcher searcher =
           new ManagementObjectSearcher(scope, query);

推荐阅读