I have a C ++ application where I use the Win32_Volume class format method. I used the following for reference:
Retrieving WMI data from the local computer
Provider Method Call
My problem is that the Format method returns with code 3 (access is denied) when the application does not start as admin. When the application is promoted, the return code is 0 (ok). The user should be able to run my application without promotion. However, the user has permission to format the disk through the Windows Format utility, so I wonder if my COM security settings are configured correctly.
hr = CoInitializeEx(0, COINIT_MULTITHREADED);
hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE,
NULL);
IWbemLocator *locator = 0;
hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&locator));
IWbemServices *service = 0;
hr = locator->ConnectServer(BSTR(L"ROOT\\CIMV2"), NULL, NULL, 0, NULL, 0, 0, &service);
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);
( , ...) ok . , . . , . !