wmi - 对 Win32_DiskDrive 类使用非管理员用户时,WMI 会出现一般故障
问题描述
我已为非管理员帐户提供了适当的权限,并且用户已添加到“分布式 COM 用户”组中。
尝试访问Win32_DiskDrive
或Win32_DiskDriveToDiskPartition
上课时,Generic Failure
出现错误。是否需要任何额外的许可?
- 如果我使用的是管理员帐户,同样的工作。
其他类,例如
Win32_NetworkAdapterConfiguration
使用非管理员帐户给出结果if (!String.IsNullOrWhiteSpace(username) && !String.IsNullOrWhiteSpace(password)) { ConnectionOptions connectionOptions = new ConnectionOptions { Impersonation = ImpersonationLevel.Impersonate, Authentication = AuthenticationLevel.PacketPrivacy, Timeout = TimeSpan.FromSeconds(60), Username = username, Password = password }; var managementScope = new ManagementScope(@"\\" + assetNameOrIpAddress + @"\root\cimv2", connectionOptions); managementScope.Connect(); managementObjectSearcher.Scope = managementScope; }
解决方案
您应该添加正确的权限
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);
推荐阅读
- node.js - 如何获取 JSON 对象列表?
- ios - 为什么在 TextField 键盘中输入的每个字母都关闭后以及如何更好地修复它?
- javascript - 将 dateTime 字符串解析为 UTC
- node.js - 怎么取?再次
- azure - 工作区身份验证:多个令牌与条件匹配
- testing - 单击赛普拉斯中的按钮
- bash - 为什么我在 bash while 循环后得到很多换行符?
- python - 使用 Gmail API 和服务帐户凭据读取 Gmail 收件箱
- google-apps-script - 模糊的 Google Apps 脚本行为
- spring-boot - Spring Boot 微服务授权