WMI Win32_卷格式方法返回拒绝访问 我有一个C++应用程序,我使用Wi32的卷类的格式方法。我参考了以下内容:
我的问题是,当应用程序不是以管理员身份运行时,Format方法返回代码3(拒绝访问)。提升应用程序时,返回代码为0(ok)。用户必须能够在没有提升的情况下运行我的应用程序。但是,用户确实有权通过Windows format utility格式化驱动器,因此我想知道我的COM安全设置是否正确WMI Win32_卷格式方法返回拒绝访问 我有一个C++应用程序,我使用Wi32的卷类的格式方法。我参考了以下内容:,c++,com,wmi,C++,Com,Wmi,我的问题是,当应用程序不是以管理员身份运行时,Format方法返回代码3(拒绝访问)。提升应用程序时,返回代码为0(ok)。用户必须能够在没有提升的情况下运行我的应用程序。但是,用户确实有权通过Windows format utility格式化驱动器,因此我想知道我的COM安全设置是否正确 //Initialize COM component hr = CoInitializeEx(0, COINIT_MULTITHREADED); //Set general COM security le
//Initialize COM component
hr = CoInitializeEx(0, COINIT_MULTITHREADED);
//Set general COM security levels
hr = CoInitializeSecurity(
NULL, // Security descriptor
-1, // COM negotiates authentication service
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication level for proxies
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation level for proxies
NULL, // Authentication info
EOAC_NONE, // Additional capabilities of the client or server
NULL); // Reserved
IWbemLocator *locator = 0;
//Create connection to WMI namespace
hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&locator));
IWbemServices *service = 0;
//Connect to the root\cimv2 namespace (location of WIN32_Volume) with the current user
hr = locator->ConnectServer(BSTR(L"ROOT\\CIMV2"), NULL, NULL, 0, NULL, 0, 0, &service);
//Set security level on the WMI conection
//Set the proxy so that impersonation of the client occurs.
hr = CoSetProxyBlanket(
service,
RPC_C_AUTHN_WINNT,
RPC_C_AUTHZ_NONE,
NULL,
RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE);
我能够检索类属性(卷标、文件系统…),无论标高如何。返回拒绝访问的只是方法调用本身。这一切都是在本地机器上完成的。如果需要更多的代码,请告诉我。谢谢