- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想检索知道其 SID 的用户 AccountName。SID 是使用 WMI 查询获取的:Select * from Win32_UserProfile
,我正在尝试使用以下查询获取用户 AccountName:
Select * from Win32_SID where SID='S-1-5-21-3949351935-1180888718-2463404063-9346'
ExecQuery
方法成功,但 IEnumWbemClassObject
中的 Next
方法失败并出现错误:H80041024 (wbemErrProviderNotCapable)。
任何帮助都会很棒。谢谢。
最佳答案
作为MSDN
文档指出,Win32_SID
WMI 类无法枚举。
因此,您不能使用 ExecQuery 方法,而是使用 IWbemServices::GetObject
函数传递正确的 WMI object path
.类似于 Win32_SID.SID='S-1-5-82-1036420768-1044797643-1061213386-2937092688-4282445334'
试试这个例子
#include "stdafx.h"
#define _WIN32_DCOM
#include <iostream>
using namespace std;
#include <comdef.h>
#include <Wbemidl.h>
# pragma comment(lib, "wbemuuid.lib")
#pragma argsused
int main(int argc, char* argv[])
{
BSTR strNetworkResource;
strNetworkResource = L"\\\\.\\root\\CIMV2";
// Initialize COM. ------------------------------------------
HRESULT hres;
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres))
{
cout << "Failed to initialize COM library. Error code = 0x" << hex << hres << endl;
cout << _com_error(hres).ErrorMessage() << endl;
cout << "press enter to exit" << endl;
cin.get();
return 1; // Program has failed.
}
// Set general COM security levels --------------------------
hres = CoInitializeSecurity(
NULL,
-1, // COM authentication
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL // Reserved
);
if (FAILED(hres))
{
cout << "Failed to initialize security. Error code = 0x" << hex << hres << endl;
cout << _com_error(hres).ErrorMessage() << endl;
CoUninitialize();
cout << "press enter to exit" << endl;
cin.get();
return 1; // Program has failed.
}
// Obtain the initial locator to WMI -------------------------
IWbemLocator *pLoc = NULL;
hres = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);
if (FAILED(hres))
{
cout << "Failed to create IWbemLocator object." << " Err code = 0x" << hex << hres << endl;
cout << _com_error(hres).ErrorMessage() << endl;
CoUninitialize();
cout << "press enter to exit" << endl;
cin.get();
return 1; // Program has failed.
}
// Connect to WMI through the IWbemLocator::ConnectServer method
IWbemServices *pSvc = NULL;
hres = pLoc->ConnectServer(
_bstr_t(strNetworkResource), // Object path of WMI namespace
NULL, // User name. NULL = current user
NULL, // User password. NULL = current
0, // Locale. NULL indicates current
NULL, // Security flags.
0, // Authority (e.g. Kerberos)
0, // Context object
&pSvc // pointer to IWbemServices proxy
);
if (FAILED(hres))
{
cout << "Could not connect. Error code = 0x" << hex << hres << endl;
cout << _com_error(hres).ErrorMessage() << endl;
pLoc->Release();
CoUninitialize();
cout << "press enter to exit" << endl;
cin.get();
return 1; // Program has failed.
}
cout << "Connected to root\\CIMV2 WMI namespace" << endl;
// Set security levels on the proxy -------------------------
hres = CoSetProxyBlanket(
pSvc, // Indicates the proxy to set
RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx
RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx
NULL, // Server principal name
RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
NULL, // client identity
EOAC_NONE // proxy capabilities
);
if (FAILED(hres))
{
cout << "Could not set proxy blanket. Error code = 0x" << hex << hres << endl;
cout << _com_error(hres).ErrorMessage() << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
cout << "press enter to exit" << endl;
cin.get();
return 1; // Program has failed.
}
// Use the IWbemServices pointer to make requests of WMI ----
IWbemClassObject *pclsObj = NULL;
hres = pSvc->GetObject(L"Win32_SID.SID='S-1-5-82-1036420768-1044797643-1061213386-2937092688-4282445334'", 0, NULL, &pclsObj, NULL);
if (FAILED(hres))
{
cout << "GetObject failed" << " Error code = 0x" << hex << hres << endl;
cout << _com_error(hres).ErrorMessage() << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
cout << "press enter to exit" << endl;
cin.get();
return 1; // Program has failed.
}
else
{
VARIANT vtProp;
HRESULT hr = pclsObj->Get(L"AccountName", 0, &vtProp, 0, 0);// String
if (!FAILED(hr))
{
if ((vtProp.vt==VT_NULL) || (vtProp.vt==VT_EMPTY))
wcout << "AccountName : " << ((vtProp.vt==VT_NULL) ? "NULL" : "EMPTY") << endl;
else
wcout << "AccountName : " << vtProp.bstrVal << endl;
}
VariantClear(&vtProp);
pclsObj->Release();
pclsObj=NULL;
}
// Cleanup
pSvc->Release();
pLoc->Release();
if (pclsObj!=NULL)
pclsObj->Release();
CoUninitialize();
cout << "press enter to exit" << endl;
cin.get();
return 0; // Program successfully completed.
}
关于C++ WMI 获取 AccountName 知道用户 SID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14482329/
对于 Windows,我可以使用哪些与 WMI 的监视和系统管理功能类似的其他框架或编程语言? 最佳答案 最能与 WMI 的性能监控功能相媲美的是 SNMP (Simple Network Manag
我的客户有一个旧的基于 DOS 的应用程序,它将格式化的输出发送到打印机。我已禁用打印,因此假脱机文件仍保留在打印队列中。我想拿起这些假脱机文件并将它们转换为 PDF 格式(然后最好删除它们)。这可能
给定一个查询,例如 SELECT * FROM WIN32_PROCESS 有没有办法查询结果对象的返回列的名称? 将结果对象中的所有行写入文本文件,例如 最佳答案 Is there a way to
谷歌让我失望,我在 MSDN 上找不到它。 man wmi在 Windows shell 上不起作用... 我正在寻找可以查询的对象列表,以及如何构建查询。 使用 WMI 我的意思是查询语言来查询诸如
我使用 .Net Framework SDK 中的 MgmtClassGen.exe 为 BizTalk 工件(例如主机、主机实例等)生成一些 WMI 包装器类。 我正在使用 HostSetting.
我正在尝试使用 WMI 获取连接到 Windows XP 计算机的硬件打印机列表。我想要的与从 Win32_Printers 获取列表不同,因为我只想获取物理上以盒子形式存在的打印机,从而消除所有“打
我查看了“root\virtualization”命名空间中的几个对象,但我无法找到 Hyper-V 存储给定虚拟机配置文件路径的位置。我需要以编程方式获取此文件路径,或者至少只是给定虚拟机的主路径也
这些都驻留在 root\RSOP\Computer 命名空间中。我得到非空结果的唯一类是 RSOP_RegistryPolicySetting ,而那个只给了我 Windows 更新和系统还原配置的设
有没有办法通过 WMI 创建/删除磁盘分区?我已经能够挂载/卸载虚拟磁盘 (vhd) 并列出它们的分区。 最佳答案 据我所知,在 WMI 中无法创建/删除分区。您可能想查看 Shell Functio
是否有用于 WMI/WBEM 的 OLEDB 提供程序? 换句话说,有人可以通过以下方式访问 WMI: shell vbscript 中的 ADO ASP 脚本中的 ADO Win32 native
我正在尝试破译 SecurityCenter.productState WMI 命名空间中的 productState 属性。 例如,产品状态是一个整数:262144 - 然后您可以查看此文档页面,将
最近很多用户在使用电脑的时候发现了wmi provider host进程占用内存比较大,不知道这个进程到底是干什么的,能不能禁止,怎么禁止。下面来一起看看想想的介绍吧。 wmi provide
我很难过,似乎无法找到明确的答案。我正在尝试通过 WMI 获取网络适配器列表。我一直在使用的命令在我们办公室的几乎所有工作站上都运行良好,没有任何问题。昨天,问题。一台机器出故障。由于它直接在用户
首先,我想说谢谢你帮我解决这个问题。非常感谢您付出的时间和努力。 标题总结得很好,但我将提供一些细节。基本上,如果我使用 C# 提取操作系统版本,它会返回适用于 Windows 8 的结果 6.2,即
我正在检测我是否正在尝试与本地主机建立连接,并创建(或不创建)WMI 连接选项,如下所示: if (NetworkUtils.IsLocalIpAddress(machineName)) {
我们如何枚举所有网络连接,以便使用 WMI 提取 VPN 连接的 IP 地址?在 XP 上,Win32_NetworkAdapterConfiguration 工作正常,但在 Vista 上它似乎只枚
我想使用 WMI(在 C++ 中)来配置静态 IPv6 地址。 使用 EnableStatic 配置静态 IPv4 地址工作正常,它是名为 Win32_NetworkAdapterConfigurat
我用这里的安装程序安装了wmi http://timgolden.me.uk/python/wmi/index.html但我无法导入模块。 这是我的代码: import wmi c=wmi.WMI()
当我尝试这样做时 SetDynamicDNSRegistration(True) 它返回“68”,我在 MSDN WMI page 上查找过它它的意思是“输入参数无效”。 完整脚本 import wm
我尝试使用 convert-vhd 命令将 VHD 转换为 VHDX,但出现以下错误: The Hyper-V Management Tools could not access an expecte
我是一名优秀的程序员,十分优秀!