I have an executable which calls CryptAcquireContext with CRYPT_NEWKEYSET:
BOOL b_result;
HCRYPTPROV prov;
b_result = CryptAcquireContext(&prov, L"testcontext6", MS_DEF_PROV, PROV_RSA_FULL, CRYPT_NEWKEYSET);
if(!b_result) {
int err = GetLastError();
fprintf(stderr, "Error acquiring context: %#x\n", err);
return 1;
}
return 0;
If I run this locally, it works fine. If I run it via WMI as follows, it returns error 0x5 (ERROR_ACCESS_DENIED):
using (var processClass = new ManagementClass(m_scope, new ManagementPath("Win32_Process"), new ObjectGetOptions()))
{
var inParams = processClass.GetMethodParameters("Create");
inParams["commandLine"] = @"cmd.exe /c C:\CppTest.exe 2>C:\test.log";
var outParams = processClass.InvokeMethod("Create", inParams, null);
return outParams["ProcessId"];
}
It seems that the environment under WMI is somehow more restrictive, which stops the new key container being created. Any suggestions for why this might be, and how to work around it?