Live Chat Icon For mobile
Live Chat Icon

How can I find all programs with a GUI (not just arbitrary windows) that are running on my local machine

Platform: WinForms| Category: Deployment

You could use EnumWindows with p/Invoke, but using the static Process.GetProcesses() found in the System.Diagnostics namespace will avoid the interop overhead.

	Using System.Diagnostics;
	foreach ( Process p in Process.GetProcesses(System.Environment.MachineName) )
		if( p.MainWindowHandle != IntPtr.Zero)
			//this is a GUI app
			Console.WriteLine( p ); // string s = p.ToString();

	Imports System.Diagnostics
	Dim p As Process
	For Each p In  Process.GetProcesses(System.Environment.MachineName)
		If p.MainWindowHandle <> IntPtr.Zero Then
			’this is a GUI app
			Console.WriteLine(p) ’ string s = p.ToString();
		End If
	Next p

There is one potential problem on Windows 98. If a process was started with ProcessStartInfo.UseShellExecute set to true, this MainWindowHandle is not available.

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.