468,491 Members | 2,114 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

Handle of all running processes

Hi...
How can i get handle of all running processes using VC++ code.
I have to find a particular window and do minimise that..
Can anyone help me.....
Dec 11 '07 #1
8 3644
Hi,
First get the snapshot of all the processes running in the system, at that time by using

CreateToolhelp32Snapshot ().

Now retrieve the info regarding the first process by using Process32First().

Open the existing process object by OpenProcess ().

Ues a loop to enumerate through all the processes. You can use

PROCESSENTRY32 pe32;
while (!Process32Next (hProcess,&pe32))

In the loop again call OpenProcess for every process.

You can get the info regarding the process from the PROCESSENTRY32 structure.

remember to close the Handles after the loop is over i.e. after the loop.
Dec 11 '07 #2
Hi,,,
Thanks for your reply...

Actually i have tried to use the CreateToolhelp32Snapshot()
but it is showing undeclared identifier error...
I am using VC++ 6.0; and using MFC. So can u please explain the above in detail form..


Thanking YOu once again....
Dec 11 '07 #3
weaknessforcats
9,207 Expert Mod 8TB
Did you #include <Tlhelp32.h> ??
Dec 11 '07 #4
Hi,

Thankx.....

I did include the header file and then got corrected...

Thankx a lot...
Dec 12 '07 #5
Hi,,
As per the previous codings
I have got the handle of all running process.
I am getting the id of all processes too.

Still my problem is unable to solve.
That is , the particular window cannot be minimized.
The ShowWindow() minimizes the application program only.

Which is the other function to do minimise or any of the operations to the window.


Thanx in advance...
Dec 12 '07 #6
How r u obtaining the Handle of a particular process ?

I think the problem might be ith the handle that u r passing in the Showwindow ()
U can get the handle of a process by using following function..

HANDLE OpenProcess(
DWORD dwDesiredAccess,
BOOL bInheritHandle,
DWORD dwProcessId
);

I have done this and it works fine.
Dec 13 '07 #7
Thanks for your reply...

I am getting handle also..

And i have tried to get control(my aim is to minimise ) over the windows which is currently running(Eg IE,OUtlook,VC editor.. like ).. The code i have done

HANDLE hproc=(HANDLE)CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS,0);
PROCESSENTRY32 pentry;
Process32First(hproc,&pentry);

HANDLE htemp;
HWND m_hactive;
while (Process32Next(hproc,&pentry))
{

HANDLE ps = OpenProcess( SYNCHRONIZE|PROCESS_TERMINATE,
FALSE,pentry.th32ProcessID);

m_hactive=(HWND)htemp;//This i have done for converting handle to hwnd.. I dont no whether it is correct
:: ShowWindow(m_hactive,SW_FORCEMINIMIZE)/*i did this first to minimising all Windows.. But does not work.*/
::TerminateProcess(htemp,GetExitCodeProcess(htemp, &tmpstr));

CloseHandle(ps)
}
Dec 13 '07 #8
Set the size of the PROCESSENTRY32 structure before using it.

Try OpenProcess () with PROCESS_ALL_ACCESS, PROCESS_SET_INFORMATION and PROCESS_QUERY_INFORMATION. The options that u have chosen are for terminating the process.

Also try to use SW_MINIMIZE instead of SW_FORCEMINIMIZE.

In good programming, always perform the NULL checks, for everything u r suspicious about.

Do let me know the results...........
Dec 14 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

11 posts views Thread by objectref | last post: by
4 posts views Thread by sneffe | last post: by
1 post views Thread by Patrick Dugan | last post: by
2 posts views Thread by Ian | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.