Click here to Skip to main content
15,906,333 members
Home / Discussions / COM
   

COM

 
GeneralAudio File identification and conversion of media files to WMA Pin
sumitkedia9-Mar-05 0:35
sumitkedia9-Mar-05 0:35 
GeneralIs it possible to catch a com event in vb or javascript Pin
grinder7-Mar-05 3:51
grinder7-Mar-05 3:51 
GeneralRe: Is it possible to catch a com event in vb or javascript Pin
rwestgraham8-Mar-05 17:41
rwestgraham8-Mar-05 17:41 
GeneralRe: Is it possible to catch a com event in vb or javascript Pin
grinder8-Mar-05 21:18
grinder8-Mar-05 21:18 
GeneralRe: Is it possible to catch a com event in vb or javascript Pin
rwestgraham9-Mar-05 23:20
rwestgraham9-Mar-05 23:20 
GeneralRe: Is it possible to catch a com event in vb or javascript Pin
grinder13-Mar-05 19:33
grinder13-Mar-05 19:33 
GeneralDCOM event sink on Terminal Services Pin
FearlessBurner7-Mar-05 2:06
FearlessBurner7-Mar-05 2:06 
GeneralWMI -> Win32_OperatingSystem Pin
Stefak6-Mar-05 13:21
Stefak6-Mar-05 13:21 
Has anyone been successful in executing the
Win32_OperatingSystem class method "Reboot" or "Shutdown" from a call to the ExecMethod routine in C++. This method works fine using VBScript. But in C++, the method returns an error in ExecMethod - WBEM_E_INVALID_METHOD_PARAMETERS.
Why ? Mad | :mad:
Here is my code :
...
HRESULT hr;
CComPtr<IWbemLocator> pLocator;
CComPtr<IWbemServices> pServices;

CComBSTR bstrPath = L"//";
bstrPath.AppendBSTR(bstrComputer);
bstrPath.Append(L"/root/cimv2");
CComBSTR bstrObject = L"Win32_OperatingSystem";
CComBSTR bstrMethod = L"Win32Shutdown";
CComBSTR bstrLanguage = SysAllocString(L"WQL");
CComBSTR bstrQuery = SysAllocString(L"select * from Win32_OperatingSystem where Primary=true");
CComBSTR bstrFlags = L"Flags";
CComBSTR bstrReserved = L"Reserved";


hr = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hr))
{
cout << "Failed in CoInitializeEx" << endl;
return hr;
}

hr = CoInitializeSecurity(
NULL,
-1, // COM negotiates service
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL // Reserved
);


if (FAILED(hr))
{
cout << "Failed in CoInitializeSecurity" << endl;
CoUninitialize();
return hr;
}

//get the initial namespace of the CIM Object Manager
hr = pLocator.CoCreateInstance(__uuidof(WbemLocator), 0, CLSCTX_INPROC_SERVER);
if (FAILED(hr)){
cout << "Failed in CoCreateInstance" << endl;
return hr;
}

//create an instance for the interface that connects WBEM services
hr = pLocator->ConnectServer(bstrPath, NULL, NULL, NULL, 0, NULL, NULL, &pServices);
if (FAILED(hr)){
cout << "Failed in ConnectServer" << endl;
return hr;
}

//authenticate to the service, using current credentials
hr = CoSetProxyBlanket(pServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE);
if (FAILED(hr)){
cout << "Failed in CoSetProxyBlanket" << endl;
return hr;
}

//query WMI for objects: get the Win32_OperatingSystem class using WQL
CComPtr<IEnumWbemClassObject> pEnumWbem;

hr = pServices->ExecQuery(bstrLanguage, bstrQuery, WBEM_FLAG_FORWARD_ONLY, NULL, &pEnumWbem);
if (FAILED(hr)){
cout << "Failed in ExecQuery" << endl;
return hr;
}

//for each returned object call Win32Shutdown
IWbemClassObject* pWbemObject;
DWORD nRetObjects;

pEnumWbem->Reset();

while (pEnumWbem->Next(WBEM_INFINITE, 1, &pWbemObject, &nRetObjects) == S_OK)
{
CComPtr<IWbemClassObject> pClass;
CComPtr<IWbemClassObject> pMethod;
CComPtr<IWbemClassObject> pInParams;
CComPtr<IWbemClassObject> pOutParams;

//get the class definition of Win32_OperatingSystem
hr = pServices->GetObject(bstrObject, 0, NULL, &pClass, NULL);
if (FAILED(hr))
{
cout << "Failed in GetObject" << endl;
pWbemObject->Release();
return hr;
}

//get our method
hr = pClass->GetMethod(bstrMethod, 0, &pMethod, NULL);
if (FAILED(hr))
{
cout << "Failed in GetMethod" << endl;
pWbemObject->Release();
return hr;
}

//create a new object for in parameters
hr = pMethod->SpawnInstance(0, &pInParams);
if (FAILED(hr))
{
cout << "Failed in SpawnInstance" << endl;
pWbemObject->Release();
return hr;
}

//add parameters
CComVariant var;
V_VT(&var) = VT_I4;
V_I4(&var) = (short)nAction;
hr = pInParams->Put(bstrFlags, 0, &var, CIM_SINT32);
if (FAILED(hr))
{
cout << "Failed in Put" << endl;
pWbemObject->Release();
return hr;
}

//call Win32Shutdown with our action
hr = pServices->ExecMethod(bstrObject, bstrMethod, 0L, NULL, pInParams, &pOutParams, NULL);

if(hr == WBEM_E_INVALID_METHOD_PARAMETERS){
cout << "That's it" << endl;
}
if (FAILED(hr)){
cout << "Failed in ExecMethod" << endl;
pWbemObject->Release();
return hr;
}

pWbemObject->Release();
}

Code Red
GeneralTransparent ActiveX Control Pin
gameengineer5-Mar-05 4:22
gameengineer5-Mar-05 4:22 
GeneralRe: Transparent ActiveX Control Pin
Pinhead_Me10-Mar-05 7:58
Pinhead_Me10-Mar-05 7:58 
GeneralRe: Transparent ActiveX Control Pin
smjones10-Mar-05 13:49
smjones10-Mar-05 13:49 
GeneralRe: Transparent ActiveX Control Pin
smjones14-Apr-05 11:57
smjones14-Apr-05 11:57 
GeneralRe: Transparent ActiveX Control Pin
Pinhead_Me18-Apr-05 5:44
Pinhead_Me18-Apr-05 5:44 
GeneralCom-Addin Query Pin
Anonymous5-Mar-05 2:14
Anonymous5-Mar-05 2:14 
GeneralWindows Hooking. Pin
technojewel3-Mar-05 20:18
technojewel3-Mar-05 20:18 
GeneralRe: Windows Hooking. Pin
Tarundeep Singh Kalra4-Mar-05 8:15
Tarundeep Singh Kalra4-Mar-05 8:15 
GeneralRe: Windows Hooking. Pin
vishalmore15-Mar-05 19:08
vishalmore15-Mar-05 19:08 
GeneralClient/Server COM+ Application Pin
Wender Oliveira3-Mar-05 14:58
Wender Oliveira3-Mar-05 14:58 
GeneralProblem While Instantiating and calling API through COM Component Pin
Anuj Mishra2-Mar-05 18:04
Anuj Mishra2-Mar-05 18:04 
GeneralIE code download failure for dll and ActiveX control using INF and CAB file Pin
prog012-Mar-05 11:40
prog012-Mar-05 11:40 
GeneralBindIFilterFromStream Pin
cheesepirate2-Mar-05 7:02
cheesepirate2-Mar-05 7:02 
Generaldyanamically create listboxes in ATL Pin
gauravjain1-Mar-05 4:28
gauravjain1-Mar-05 4:28 
GeneralCommunication with one particular instance of an activex/com object Pin
awhit1-Mar-05 0:54
awhit1-Mar-05 0:54 
GeneralCOM and MSFlexGrid Pin
A. Karthick Arun28-Feb-05 20:34
A. Karthick Arun28-Feb-05 20:34 
GeneralCOM,OLE,AUTOMATION,ActiveX Pin
hjkjk28-Feb-05 20:16
hjkjk28-Feb-05 20:16 

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.