-
May 24th, 2006, 04:30 AM
#1
Searching a Process
Actually what I'm trying to do is to check whether Babylon is running or not. I've tried using FindWindow and it worked but it didn't when babylon was minimized to the system tray. So I thought that I should try and search the process name of babylon which is "Babylon.exe" but I don't know how to do so in C++, any ideas?
Thanks,
-
May 24th, 2006, 04:37 AM
#2
Re: Searching a Process
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
-
May 24th, 2006, 07:14 AM
#3
Re: Searching a Process
you can use tlhelp functions.
here is a code i wrote while ago that demonstrates how to get list of all process running in the system.
Code:
#include <windows.h>
#include <tlhelp32.H>
#include <iostream>
using namespace::std;
int main()
{
HANDLE process;
PROCESSENTRY32 ProcessList;
process = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (process == INVALID_HANDLE_VALUE)
{
return 0;
}
while(Process32Next(process, &ProcessList) != FALSE)
{
cout << ProcessList.szExeFile << " " << ProcessList.th32ProcessID << endl;
}
return 0;
}
-
May 24th, 2006, 07:22 AM
#4
Re: Searching a Process
Originally Posted by Replica
you can use tlhelp functions.
here is a code i wrote while ago that demonstrates how to get list of all process running in the system.
Code:
#include <windows.h>
#include <tlhelp32.H>
#include <iostream>
using namespace::std;
int main()
{
HANDLE process;
PROCESSENTRY32 ProcessList;
process = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (process == INVALID_HANDLE_VALUE)
{
return 0;
}
while(Process32Next(process, &ProcessList) != FALSE)
{
cout << ProcessList.szExeFile << " " << ProcessList.th32ProcessID << endl;
}
return 0;
}
few more codes you have to use in your program to get all the running process
have a look for
Code:
//get First Process
Process32First()
//Get Next Process
Process32Next ()
Thanx
-
May 24th, 2006, 07:28 AM
#5
Re: Searching a Process
Sorry guys, all of these solutions looks very crude. Isn't there something more elegant for enumerating processes in C++.
I've tried the EnumProcesses in Psapi.h but it didn't compile, I needed to add the psapi.lib but it falls in runtime, GetProcessImageFileNameA is not found in PSAPI.dll, I can't continue from here ...
I'll try later the second solution and see if it is more usefull.
Thank's anyway.
-
May 24th, 2006, 07:31 AM
#6
Re: Searching a Process
Originally Posted by humptydumpty
few more codes you have to use in your program to get all the running process
have a look for
Code:
//get First Process
Process32First()
//Get Next Process
Process32Next ()
Thanx
actually, it dosen't really matter.
in both ways it shows all the running processes, and i've already checked it.
-
May 24th, 2006, 07:36 AM
#7
Re: Searching a Process
Originally Posted by nfireman
Sorry guys, all of these solutions looks very crude. Isn't there something more elegant for enumerating processes in C++.
I've tried the EnumProcesses in Psapi.h but it didn't compile, I needed to add the psapi.lib but it falls in runtime, GetProcessImageFileNameA is not found in PSAPI.dll, I can't continue from here ...
I'll try later the second solution and see if it is more usefull.
Thank's anyway.
::GetProcessImageFileName() is part of the PSDK so either install it, or use dynamic loading:
Code:
typedef DWORD (WINAPI *tGetProcessImageFileNameA )(HANDLE,LPTSTR,DWORD );
tGetProcessImageFileNameA pGetProcessImageFileNameA=0;
HINSTANCE handle = ::LoadLibrary("Psapi.dll");
if ( handle == 0 )
return;
if (handle)
pGetProcessImageFileNameA = (tGetProcessImageFileNameA) ::GetProcAddress(handle,"GetProcessImageFileNameA");
if ( pGetProcessImageFileNameA)
{
// call function
//pGetProcessImageFileNameA();
}
::FreeLibrary(handle);
BTW: it is available only on XP.
Cheers
-
May 24th, 2006, 07:39 AM
#8
Re: Searching a Process
Yes i know .did u checked my post i never said it's wrong
But i just want to say .that if u explain a code to someone it sould be easy to understand
that'all
thanx
-
May 24th, 2006, 10:39 AM
#9
Re: Searching a Process
By the way, I'm using Windows2000. It's an organizational decision not mine :-) sorry ...
-
May 24th, 2006, 10:50 PM
#10
Re: Searching a Process
Interesting, why does FindWindow fail ? Are you sure when you minimize to tray you are not destroying the "babylon" window ?
-
May 24th, 2006, 10:52 PM
#11
Re: Searching a Process
BTW, is this babylon.exe one of your apps that you have code for , or is it third party app ?
-
May 25th, 2006, 03:09 AM
#12
Re: Searching a Process
Originally Posted by kirants
BTW, is this babylon.exe one of your apps that you have code for , or is it third party app ?
Babylon is a comercial program (www.babylon.com) for translation, my mistake that I assumed it's known.
Originally Posted by kirants
Interesting, why does FindWindow fail ? Are you sure when you minimize to tray you are not destroying the "babylon" window ?
I don't know whether the window is destroyed or not!
Anyway I've liked much the solution of "Replica" it worked great for me without the need to add any libraries or to load externally dll.
Actually I don't understand why this issue is so problematic and unintuitive. In the .NET its a breeze to do this things :-)
-
May 26th, 2006, 05:45 AM
#13
Re: Searching a Process
There is another alternative.. WMI.
You can issue a WMI query like,
SELECT ProcessId FROM Win32_Process WHERE Name = 'babylon.exe'
That will return process id's associated with each instance of babylon.exe running
create a pid_array from the result set
foreach pid in pid_array
{
p = OpenProcess( ...., pid )
kill(p);
}
Note: this is not actual code just to show the method.
For more info about WMI see:
http://msdn.microsoft.com/library/de...start_page.asp
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|