Click here to Skip to main content
15,899,007 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to get ProcessId From Hinstance? Pin
Michael Dunn20-Apr-06 8:45
sitebuilderMichael Dunn20-Apr-06 8:45 
GeneralRe: How to get ProcessId From Hinstance? Pin
Old Gun20-Apr-06 16:54
Old Gun20-Apr-06 16:54 
QuestionHow to use Widcomm bluetooth driver in my application? Pin
MarekKoprla20-Apr-06 5:22
MarekKoprla20-Apr-06 5:22 
QuestionProblem in CFileDialog Pin
Sarvan AL20-Apr-06 4:45
Sarvan AL20-Apr-06 4:45 
QuestionRe: Problem in CFileDialog Pin
David Crow20-Apr-06 5:59
David Crow20-Apr-06 5:59 
AnswerRe: Problem in CFileDialog Pin
jayart20-Apr-06 6:14
jayart20-Apr-06 6:14 
Questionsome image component (showing and sending to printer) Pin
cassio marques20-Apr-06 4:45
cassio marques20-Apr-06 4:45 
QuestionCalling WIN32_Service::ChangeStartMode with C++ Pin
qrverona20-Apr-06 4:13
qrverona20-Apr-06 4:13 
Dear all,
I'm writing a small application that manages the Themes service using WMI.
Unfortunately I have problems with the parameters. The API documentation says that it is a string, but I wasn't able to find a solution.

ExecMethod returns : WBEM_E_INVALID_METHOD_PARAMETERS = 0x8004102f

I have realized that the parameter is not well formatted, but I'm not able to find any tip.

Notice that the same code querying for "Win32_Process" and calling "Create" using CommandLine as parameter and "notepad.exe" as value, runs correctly. To test it, it is enough to replace the strings text.

Thanks

Daniele


// some WMI initialization here.....

IWbemClassObject *pClass = NULL;
IWbemClassObject *pInParams = NULL;
IWbemClassObject *pInParamInstance = NULL;
IWbemClassObject *pOutParams = NULL;

IEnumWbemClassObject *pEnumerator = NULL;
IWbemClassObject *pInstance = NULL;
DWORD dwCount = 0;

HRESULT hres;


BSTR bstrChangeStartMode = L"ChangeStartMode";
BSTR bstrClassName = L"Win32_Service";
BSTR bstrParamName = L"StartMode";
BSTR bstrParamValue = L"Automatic";

VARIANT varValue;
VARIANT varReturnValue;




// query for the proper object to which apply the method
hres = pSvc->ExecQuery( bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_Service Where Name = 'Themes'"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);

while (pEnumerator->Next( WBEM_INFINITE, 1,&pInstance, &dwCount) == WBEM_S_NO_ERROR)
{

// get method class
hres = pSvc->GetObject( bstrClassName, 0, NULL, &pClass, NULL);

// prepare method params
if (pClass)
hres = pClass->GetMethod(bstrChangeStartMode,0,&pInParams,NULL);
else
{
printf("Unable to get method '%s' from '%s' class\n", CString(bstrChangeStartMode), CString(bstrClassName));
return -1;
}


if (pInParams)
hres = pInParams->SpawnInstance(0, &pInParamInstance);
else
{
printf("Unable to get params for from %s::%s()\n",
CString(bstrClassName),
CString(bstrChangeStartMode));

return -2;
}


// analyzing the method paramenter (debug purposes only)
printf("Analyzing the %s::%s() paramenter(s)...\n",
CString(bstrClassName),
CString(bstrChangeStartMode));

hres = pInParams->BeginEnumeration(0);
BSTR pName = NULL;

while ((pInParams->Next(NULL, &pName, NULL, NULL, NULL)) == BEM_S_NO_ERROR)
{
CString s(pName);
printf("Property value: %s\n", s);
}

pInParams->EndEnumeration();
printf("\n");


// Create the values for the in-parameters

VariantInit(&varValue);

varValue.vt = VT_BSTR;
varValue.bstrVal = bstrParamValue;

// assign a value to the option...
if (pInParamInstance)
hres = pInParamInstance->Put( bstrParamName, 0,
&varValue,
0);

else
{
printf("Unable to create params instance for %s::%s()\n",
CString(bstrClassName),
CString(bstrChangeStartMode));

return -3;
}

if (hres != S_OK)
return -4;

// Execute Method
hres = pSvc->ExecMethod(bstrClassName, // class
bstrChangeStartMode, // method
0, // synchronous call NULL, //
pInParamInstance, // input
&pOutParams, // output
NULL);
if (hres != S_OK)
break;

} // end while pEnumerator

if (pEnumerator)
pEnumerator->Release();

} // end query....


if (hres != S_OK)
{
printf("Exec method for %s::%s() returned 0x%08X\n\n",
CString(bstrClassName),
CString(bstrChangeStartMode),
hres);

}






Daniele
Questionagain question Pin
messages20-Apr-06 3:56
messages20-Apr-06 3:56 
QuestionRe: again question Pin
David Crow20-Apr-06 4:28
David Crow20-Apr-06 4:28 
AnswerRe: again question Pin
messages20-Apr-06 4:44
messages20-Apr-06 4:44 
GeneralRe: again question Pin
David Crow20-Apr-06 5:57
David Crow20-Apr-06 5:57 
GeneralRe: again question Pin
messages20-Apr-06 19:33
messages20-Apr-06 19:33 
AnswerRe: again question Pin
Mila02520-Apr-06 4:45
Mila02520-Apr-06 4:45 
GeneralRe: again question Pin
messages20-Apr-06 5:11
messages20-Apr-06 5:11 
Questionoutput stream problem Pin
Aqueel20-Apr-06 3:41
Aqueel20-Apr-06 3:41 
AnswerRe: output stream problem Pin
toxcct20-Apr-06 3:54
toxcct20-Apr-06 3:54 
GeneralRe: output stream problem Pin
Aqueel20-Apr-06 3:58
Aqueel20-Apr-06 3:58 
AnswerRe: output stream problem Pin
David Crow20-Apr-06 4:29
David Crow20-Apr-06 4:29 
GeneralRe: output stream problem Pin
Aqueel20-Apr-06 4:42
Aqueel20-Apr-06 4:42 
GeneralRe: output stream problem Pin
Aqueel20-Apr-06 4:47
Aqueel20-Apr-06 4:47 
GeneralRe: output stream problem Pin
jayart20-Apr-06 5:14
jayart20-Apr-06 5:14 
QuestionPersistent Toolbars Pin
Sarvan AL20-Apr-06 1:41
Sarvan AL20-Apr-06 1:41 
QuestionHow do i dynamically acces method export in CLASS Pin
Killer320-Apr-06 0:54
Killer320-Apr-06 0:54 
AnswerRe: How do i dynamically acces method export in CLASS Pin
Naveen20-Apr-06 1:08
Naveen20-Apr-06 1:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.