473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 3855
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,208 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

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

Similar topics

11
by: objectref | last post by:
Hi to all, is there a way to get the window handle of the main window of an application or process ? For example, if someone opens Microsoft Word, he gets a window so he/she can write text....
1
by: Fei Yuan | last post by:
Please forgive me re-posting this question since I wasn't clear in my original post. --------> Starting an external process needs to pass it a ProcessStartInfo() object. ProcessStartInfo has a...
3
by: Jarod_24 | last post by:
Dim p As Diagnostics.Process Debug.WriteLine(p.Id) Debug.WriteLine(p.Handle) What is the difference between a process's ID and Handle I see that they are different, and i know that the...
4
by: sneffe | last post by:
Hi, im writing a program to keep track of which programs is currently running. I would like to have the caption of running programs displayed in a textbox on my form. I cant seem to find an easy way...
1
by: Patrick Dugan | last post by:
Is it possible to get the handle of a running service? I have a program (ActiveX program) running in memory. When I start my service I need to pass the service's handle to that program in order...
0
by: Gary | last post by:
Hi, there, I need to get the handle of a running excel application. However, there is no HWnd property. Following is my code: --------------------------------------------------------------...
2
by: Ian | last post by:
Hi, Is anybody aware of problems in .NET where the handle count of an application increases over time? We have a server application that is hosted in a Windows Service and accepts socket...
2
by: Gary | last post by:
Hi i need to work with windows of processes that are running on my pc from a certain programme. I've figured out how to build an array of processes that contain just the processes i'm interested in...
2
by: Tim | last post by:
Hey guys, I tried to get a process handle with the following code snippet: 00 Process processes = Process.GetProcesses(); 01 if (null != processes && processes.Length 0) 02 { 03 foreach...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.