- Joined
- Apr 20, 2009
- Messages
- 1
- Reaction score
- 0
[font=Verdana, Arial, Helvetica]Hey,
Im trying to kill a process by name. I have used the msdn example code of
killing a process by pid. I wrote a method to get the pid using the name of
the process, and its working fine till i get the pid and store it in a
variable called ProcId.
The problem is how do i include the ProcId in the method call::::::
I have done it like this
BSTR ClassNameInstance = SysAllocString(
L"Win32_Process.Handle=\""+ProcId+"\"");
and it says error C2110: '+' : cannot add two pointers
HELP ME OUT
Here is my Code.... ---------------------------------------------------------------------------------------------------------------------------------------
IEnumWbemClassObject* pEnumerator = NULL;
BSTR bstrQry=(L"Select * from win32_Process WHERE Name=\"notepad.exe\"");
hres = pSvc->ExecQuery(
L"WQL",
L"Select * from win32_Process WHERE Name=\"notepad.exe\"" ,
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres))
{
cout << "\nQuery for operating system name failed.";
cout<< "\n Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
}
cout << "\n Query excution sucessful \n";
// GET THE DATA FROM THE QUERY....
//----------------------------------------------------------------------------------------------------
// IWbemClassObject :: Contains and manipulates both class definitions and
class object instances.
// Developers need not implement this interface; WMI
provides its implementation. //----------------------------------------------------------------------------------------------------
IWbemClassObject *pclsObj;
ULONG uReturn = 0;
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if(0 == uReturn)
{
exit(0);
}
VARIANT vtProp;
VariantInit(&vtProp);
//----------------------------------------
// GET THE VALUE OF THE PID property.....
//----------------------------------------
hr = pclsObj->Get(L"ProcessId", 0, &vtProp, 0, 0);
int ProcId=(int)vtProp.iVal;
// Set up to call the Win32_Process::Create method
BSTR ClassName = SysAllocString(L"Win32_Process");
BSTR ClassNameInstance = SysAllocString(
L"Win32_Process.Handle=\""+ProcId+"\""); //KILLING THE PROCESS
HERE....
_bstr_t MethodName = (L"Terminate");
BSTR ParameterName = SysAllocString(L"Reason");
IWbemClassObject* pClass = NULL;
hres = pSvc->GetObject(ClassName, 0, NULL, &pClass, NULL);
IWbemClassObject* pInParamsDefinition = NULL;
IWbemClassObject* pOutMethod = NULL;
hres = pClass->GetMethod(MethodName, 0,
&pInParamsDefinition, &pOutMethod); ---------------------------------------------------------------------------------------------------------------------------------------[/font]
Im trying to kill a process by name. I have used the msdn example code of
killing a process by pid. I wrote a method to get the pid using the name of
the process, and its working fine till i get the pid and store it in a
variable called ProcId.
The problem is how do i include the ProcId in the method call::::::
I have done it like this
BSTR ClassNameInstance = SysAllocString(
L"Win32_Process.Handle=\""+ProcId+"\"");
and it says error C2110: '+' : cannot add two pointers
HELP ME OUT
Here is my Code.... ---------------------------------------------------------------------------------------------------------------------------------------
IEnumWbemClassObject* pEnumerator = NULL;
BSTR bstrQry=(L"Select * from win32_Process WHERE Name=\"notepad.exe\"");
hres = pSvc->ExecQuery(
L"WQL",
L"Select * from win32_Process WHERE Name=\"notepad.exe\"" ,
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres))
{
cout << "\nQuery for operating system name failed.";
cout<< "\n Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
}
cout << "\n Query excution sucessful \n";
// GET THE DATA FROM THE QUERY....
//----------------------------------------------------------------------------------------------------
// IWbemClassObject :: Contains and manipulates both class definitions and
class object instances.
// Developers need not implement this interface; WMI
provides its implementation. //----------------------------------------------------------------------------------------------------
IWbemClassObject *pclsObj;
ULONG uReturn = 0;
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if(0 == uReturn)
{
exit(0);
}
VARIANT vtProp;
VariantInit(&vtProp);
//----------------------------------------
// GET THE VALUE OF THE PID property.....
//----------------------------------------
hr = pclsObj->Get(L"ProcessId", 0, &vtProp, 0, 0);
int ProcId=(int)vtProp.iVal;
// Set up to call the Win32_Process::Create method
BSTR ClassName = SysAllocString(L"Win32_Process");
BSTR ClassNameInstance = SysAllocString(
L"Win32_Process.Handle=\""+ProcId+"\""); //KILLING THE PROCESS
HERE....
_bstr_t MethodName = (L"Terminate");
BSTR ParameterName = SysAllocString(L"Reason");
IWbemClassObject* pClass = NULL;
hres = pSvc->GetObject(ClassName, 0, NULL, &pClass, NULL);
IWbemClassObject* pInParamsDefinition = NULL;
IWbemClassObject* pOutMethod = NULL;
hres = pClass->GetMethod(MethodName, 0,
&pInParamsDefinition, &pOutMethod); ---------------------------------------------------------------------------------------------------------------------------------------[/font]