WMI Method Win32_Volume Format Returns Denied Access

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.

//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);

( , ...) ok . , . . , . !

+4
1

WMIC, (, : Win32_DiskDrive, Win32_DiskPartition, Win32_LogicalDisk . WMIC .

Windows Format Tool .

+1

Source: https://habr.com/ru/post/1530870/


All Articles