RE: Using StdRegProv::SetDWORDValue in C++
- From: Brian Geisel <Brian Geisel@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 14 Mar 2007 16:18:03 -0700
Hey Luke,
Yes, I know what you mean ;-) For the hDefKey attribute, set:
varCommand.vt = VT_I4;
varCommand.lVal = (long)HKEY_LOCAL_MACHINE;
You can, of course, use the value. I just put the HKEY define for
readability. Anyway, I believe it is VT_I4 that you were looking for.
-Brian
"luke_21" wrote:
Hi,.
Here is my code to change a registry DWORD value on a foreign box by
WMI.
IWbemLocator *ppiWmiLoc = NULL;
hres = CoCreateInstance(CLSID_WbemLocator,0,CLSCTX_INPROC_SERVER,
IID_IWbemLocator,
(LPVOID *) &ppiWmiLoc);
IWbemServices *pSvc = NULL;
CComBSTR bstrserv(L"\\\\MyComputer\\root\\default");
CComBSTR bstrUsername(m_csUserName), bstrPassword(m_csPassword);
hres = ppiWmiLoc->ConnectServer(bstrserv, NULL, NULL,0, NULL, 0, 0,
&pSvc);
if(SUCCEEDED(hres))
{
hres = CoSetProxyBlanket(pSvc, RPC_C_AUTHN_WINNT,
RPC_C_AUTHZ_NONE,
NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL,
EOAC_NONE);
if(SUCCEEDED(hres))
{
// Connect to the local root\cimv2 namespace
// and obtain pointer pSvc to make IWbemServices calls.
BSTR MethodName = SysAllocString(L"SetDWORDValue");
BSTR ClassName = SysAllocString(L"StdRegProv");
IWbemClassObject* pClass = NULL;
hres = pSvc->GetObject(ClassName, 0, NULL, &pClass, NULL);
if(SUCCEEDED(hres))
{
IWbemClassObject* pInParamsDefinition = NULL;
hres = pClass->GetMethod(MethodName, 0,
&pInParamsDefinition, NULL);
if(SUCCEEDED(hres))
{
IWbemClassObject* pClassInstance = NULL;
hres = pInParamsDefinition->SpawnInstance(0, &pClassInstance);
if(SUCCEEDED(hres))
{
/*// Create the values for the in parameters
VARIANT varCommand;
varCommand.vt = VT_UINT;
varCommand.uintVal = &H80000002;
// Store the value for the in parameters
hres = pClassInstance->Put(L"hDefKey", 0,
&varCommand, 0);*/
// Create the values for the in parameters
VARIANT varCommand;
varCommand.vt = VT_BSTR;
varCommand.bstrVal = L"System\CurrentControlSet\Control\Lsa";
// Store the value for the in parameters
hres = pClassInstance->Put(L"sSubKeyName", 0,
&varCommand, 0);
// Create the values for the in parameters
varCommand.vt = VT_BSTR;
varCommand.bstrVal = L"ForceGuest";
// Store the value for the in parameters
hres = pClassInstance->Put(L"sValueName", 0,
&varCommand, 0);
// Create the values for the in parameters
varCommand.vt = VT_I4;
varCommand.lVal = 0;
// Store the value for the in parameters
hres = pClassInstance->Put(L"lValue", 0,
&varCommand, CIM_UINT8);
// Execute Method
IWbemClassObject* pOutParams = NULL;
hres = pSvc->ExecMethod(ClassName, MethodName, 0,
NULL, pClassInstance, &pOutParams, NULL);
if (FAILED(hres))
{
MessageBox("Command Failed","SetStringValue",MB_OK);
/* VariantClear(&varCommand);
SysFreeString(ClassName);
SysFreeString(MethodName);
pClass->Release();
pInParamsDefinition->Release();
pOutParams->Release();
pSvc->Release();*/
}
else
{
VARIANT varReturnValue;
CComBSTR bstrret(L"ReturnValue");
BSTR ret;
hres = pOutParams->GetObjectText(0, &ret);
char mess[MAX_PATH];
wsprintf(mess,"%S",ret);
MessageBox(mess,"Error message",MB_OK);
/*hres = pOutParams->Get(bstrret, 0, &varReturnValue, NULL,
0);
SHORT toto = varReturnValue.iVal;*/
}
pClassInstance->Put function needs a Variant. So
I have to pass a dword, but by the variant. As I passed my string
value by Variant : var.vt = VT_BSTR and then var.bstrval =
L"MyVariant"; Do you know what I mean ? I have to find the exact type
I have to use and the exact format I have to use for my DWORD value.
IWbemClassObject* pClassInstance;
HRESULT Put(
LPCWSTR wszName,
LONG lFlags,
VARIANT* pVal,
CIMTYPE vtType
);
- References:
- Using StdRegProv::SetDWORDValue in C++
- From: luke_21
- Using StdRegProv::SetDWORDValue in C++
- Prev by Date: Query and Set MPIO Load Balance Policy
- Next by Date: Re: Some Basic WMI questions
- Previous by thread: Using StdRegProv::SetDWORDValue in C++
- Next by thread: RE: Error 0x80041001 retrieving some WMI data in Windows 2003 SP1
- Index(es):
Relevant Pages
|