473,224 Members | 1,658 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,224 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 3847
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: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.