Christian de Bellefeuille
asked on
Get a list of running applications
I would like to know how i could get a list of applications running on Windows (only those who have a graphical window, not the process list).
Anyone can help?
Thank you
Anyone can help?
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think it's not a big deal, depends where to used it; but it's much better and shorter. Nice simple code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
//for Process.GetCurrentProcess
using System.Diagnostics;
namespace WindowsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void getwinlist()
{
int myId = Process.GetCurrentProcess().Id;
foreach (Process p in Process.GetProcesses())
if (p.Id != myId && p.MainWindowHandle != IntPtr.Zero)
listBox1.Items.Add(p.ProcessName);
}
private void Form1_Load(object sender, EventArgs e)
{
getwinlist();
}
}
}
systan, that's almost word-for-word the code I just posted (http:#a35132200). ;)
ASKER
sorry guys i didn't had time to test the solutions, and it's late. I'll test that tomorrow morning.
thanks
thanks
Yes, I told you that it's much better and shorter. Nice simple code.
ASKER
ok i've just tried both codes. They both work.
I'll attribute a bit more points to tgerbert version because i agree with him, an application might not have a window title. It might be rare, but it's the case (ex: explorer.exe doesn't have any title, but it's important to list it in my case).
I'll attribute a bit more points to tgerbert version because i agree with him, an application might not have a window title. It might be rare, but it's the case (ex: explorer.exe doesn't have any title, but it's important to list it in my case).
ASKER
Thanks a lot to both of you
Checking the MainWindowTitle isn't a good idea, it's entirely possible there will be applicatons open with forms that have no title.
@cdebel
If you want to exclude the current process (i.e. you don't want to find yourself), you can just tweak the code slightly:
Open in new window
Or:
Open in new window