L
LChambers
Hello,
I found several examples to use SetStringValue and SetDWORDValue in
Default\StdRegProv.
They all are in VB language and i'm using C++ in my applications.
For example I try to disable UAC on VISTA OS boxes remotly but I have
a ReturnValue = 0 each time I try to execute my Method. I think
parameters are right but It puts value "3" in the registry entry.
Could someone help me ?
hres = CoCreateInstance(CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &ppiWmiLoc);
IWbemServices *pSvc = NULL;
CComBSTR bstrserv(L"\\\\VISTABOX\\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))
{
BSTR MethodName = SysAllocString(L"SetStringValue");
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-
&pClassInstance);
if(SUCCEEDED(hres))
{
VARIANT varCommand;
varCommand.vt = VT_BSTR;
varCommand.bstrVal =
L"SOFTWARE
\Microsoft\Windows\CurrentVersion\Policies\System\\";
hres =
pClassInstance-
&varCommand, 0);
varCommand.vt = VT_BSTR;
varCommand.bstrVal =
L"legalnoticecaption";
hres = pClassInstance-
&varCommand, 0);
VARIANT lvar;
VariantInit(&lvar);
lvar.vt = VT_BSTR;
lvar.bstrVal = L"Notice";
// Store the value for the in
parameters
hres = pClassInstance-
0);
// Execute Method
IWbemClassObject* pOutParams =
NULL;
hres = pSvc-
MethodName, 0, NULL, pClassInstance,
&pOutParams, NULL);
if (FAILED(hres))
{
MessageBox("Command
Failed","SetStringValue",MB_OK);
}
else
{
CComBSTR
bstrClassObj;
hres = pOutParams-
&(bstrClassObj.m_str));
USES_CONVERSION;
std::string
mess(OLE2T(bstrClassObj));
MessageBox(mess.c_str(),"Error
message",MB_OK);
}
}
else
AfficheErreur(hres);
}
else
AfficheErreur(hres);
}
else
AfficheErreur(hres);
}
I found several examples to use SetStringValue and SetDWORDValue in
Default\StdRegProv.
They all are in VB language and i'm using C++ in my applications.
For example I try to disable UAC on VISTA OS boxes remotly but I have
a ReturnValue = 0 each time I try to execute my Method. I think
parameters are right but It puts value "3" in the registry entry.
Could someone help me ?
hres = CoCreateInstance(CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &ppiWmiLoc);
IWbemServices *pSvc = NULL;
CComBSTR bstrserv(L"\\\\VISTABOX\\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))
{
BSTR MethodName = SysAllocString(L"SetStringValue");
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))
{
VARIANT varCommand;
varCommand.vt = VT_BSTR;
varCommand.bstrVal =
L"SOFTWARE
\Microsoft\Windows\CurrentVersion\Policies\System\\";
hres =
pClassInstance-
Put(L"sSubKeyName", 0,
&varCommand, 0);
varCommand.vt = VT_BSTR;
varCommand.bstrVal =
L"legalnoticecaption";
hres = pClassInstance-
Put(L"sValueName", 0,
&varCommand, 0);
VARIANT lvar;
VariantInit(&lvar);
lvar.vt = VT_BSTR;
lvar.bstrVal = L"Notice";
// Store the value for the in
parameters
hres = pClassInstance-
&lvar,Put(L"sValue", 0,
0);
// Execute Method
IWbemClassObject* pOutParams =
NULL;
hres = pSvc-
ExecMethod(ClassName,
MethodName, 0, NULL, pClassInstance,
&pOutParams, NULL);
if (FAILED(hres))
{
MessageBox("Command
Failed","SetStringValue",MB_OK);
}
else
{
CComBSTR
bstrClassObj;
hres = pOutParams-
GetObjectText(0,
&(bstrClassObj.m_str));
USES_CONVERSION;
std::string
mess(OLE2T(bstrClassObj));
MessageBox(mess.c_str(),"Error
message",MB_OK);
}
}
else
AfficheErreur(hres);
}
else
AfficheErreur(hres);
}
else
AfficheErreur(hres);
}