|
|
|
@ -82,10 +82,9 @@ namespace wmic
|
|
|
|
|
std::cout << "Connected to ROOT\\CIMV2 WMI namespace" << std::endl;
|
|
|
|
|
|
|
|
|
|
// Set security levels for the proxy
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
hres = CoSetProxyBlanket(
|
|
|
|
|
service_ptr, // Indicates the proxy to set
|
|
|
|
|
service_ptr, // 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
|
|
|
|
@ -110,9 +109,72 @@ namespace wmic
|
|
|
|
|
BSTR method_name = SysAllocString(L"Create");
|
|
|
|
|
BSTR class_name = SysAllocString(L"Win32_Process");
|
|
|
|
|
|
|
|
|
|
IWbemClassObject* class_ptr = nullptr;
|
|
|
|
|
hres = service_ptr->GetObjectA(class_name, 0, 0, &class_ptr, 0);
|
|
|
|
|
|
|
|
|
|
IWbemClassObject* param_def_ptr = nullptr;
|
|
|
|
|
hres = class_ptr->GetMethod(method_name, 0, ¶m_def_ptr, 0);
|
|
|
|
|
|
|
|
|
|
IWbemClassObject* class_inst_ptr = nullptr;
|
|
|
|
|
hres = param_def_ptr->SpawnInstance(0, &class_inst_ptr);
|
|
|
|
|
|
|
|
|
|
// Create values for in parameter
|
|
|
|
|
//
|
|
|
|
|
VARIANT var_cmd;
|
|
|
|
|
var_cmd.vt = VT_BSTR;
|
|
|
|
|
var_cmd.bstrVal = _bstr_t("notepad.exe");
|
|
|
|
|
|
|
|
|
|
// Store the value for the in parameters
|
|
|
|
|
//
|
|
|
|
|
hres = class_inst_ptr->Put(L"CommandLine", 0,
|
|
|
|
|
&var_cmd, 0);
|
|
|
|
|
wprintf(L"The command is: %s\n", V_BSTR(&var_cmd));
|
|
|
|
|
|
|
|
|
|
// Execute
|
|
|
|
|
//
|
|
|
|
|
IWbemClassObject* pOutParams = NULL;
|
|
|
|
|
hres = service_ptr->ExecMethod(class_name, method_name, 0,
|
|
|
|
|
NULL, class_inst_ptr, &pOutParams, NULL);
|
|
|
|
|
|
|
|
|
|
if (FAILED(hres))
|
|
|
|
|
{
|
|
|
|
|
std::cout << "Could not execute method. Error code = 0x"
|
|
|
|
|
<< std::hex << hres << std::endl;
|
|
|
|
|
VariantClear(&var_cmd);
|
|
|
|
|
SysFreeString(class_name);
|
|
|
|
|
SysFreeString(method_name);
|
|
|
|
|
class_ptr->Release();
|
|
|
|
|
class_inst_ptr->Release();
|
|
|
|
|
param_def_ptr->Release();
|
|
|
|
|
pOutParams->Release();
|
|
|
|
|
service_ptr->Release();
|
|
|
|
|
loc_ptr->Release();
|
|
|
|
|
CoUninitialize();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// To see what the method returned - use the following code.
|
|
|
|
|
// The return value will be in &varReturnValue
|
|
|
|
|
//
|
|
|
|
|
VARIANT varReturnValue;
|
|
|
|
|
hres = pOutParams->Get(_bstr_t(L"ReturnValue"), 0,
|
|
|
|
|
&varReturnValue, NULL, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
|
//
|
|
|
|
|
VariantClear(&var_cmd);
|
|
|
|
|
VariantClear(&varReturnValue);
|
|
|
|
|
SysFreeString(class_name);
|
|
|
|
|
SysFreeString(method_name);
|
|
|
|
|
class_ptr->Release();
|
|
|
|
|
class_inst_ptr->Release();
|
|
|
|
|
param_def_ptr->Release();
|
|
|
|
|
pOutParams->Release();
|
|
|
|
|
loc_ptr->Release();
|
|
|
|
|
service_ptr->Release();
|
|
|
|
|
CoUninitialize();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|