我为非管理员帐户提供了appropriate permission,并且该用户已添加到“分布式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;
}
答案 0 :(得分:0)
您应该添加正确的权限
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);