Hi i need to get all running application not process and then list it in a listview
Thank you but by the way can any one tell me how can i do an action to the selected element of a listview on buttonclick
thank you all again this will help me alot

Dani AI

Generated

Short, practical plan that builds on 's suggestion to treat "applications" as top-level windows and then shows how to act on the selected item in a ListView.

Start by populating each ListView row with a compact descriptor (window title, process name, PID). Put the PID (or a small DTO with PID + window handle) into the ListViewItem.Tag so the UI keeps only lightweight data and not a long‑lived Process object. This makes later lookups simple and avoids holding resources for processes that may exit.

On the button click, read the selected item, recover the PID from Tag, then fetch the live Process by id and perform the action you need (bring to front, send close, force kill, etc.). Example pattern for a WinForms button click (error handling omitted for clarity):

// button click handler (WinForms)
if (listView1.SelectedItems.Count == 0) return;
int pid = (int)listView1.SelectedItems[0].Tag;
var proc = Process.GetProcessById(pid);
// bring window to foreground (P/Invoke signature required elsewhere)
if (proc.MainWindowHandle != IntPtr.Zero) SetForegroundWindow(proc.MainWindowHandle);

Important practical notes and gotchas:

  • Processes can exit anytime. Wrap lookups and actions in try/catch and verify proc.HasExited before calling members.
  • Accessing MainModule or process internals may throw Win32Exception for protected processes or require elevation; test under normal and elevated accounts.
  • For long-running enumeration use a background thread/task and marshal ListView updates to the UI thread (Invoke/BeginInvoke) to avoid cross-thread exceptions.
  • Prefer CloseMainWindow for a graceful shutdown and only use Kill as a last resort — it can cause data loss and may require admin rights.
  • If you need more accurate "window" detection than Process properties, use Win32 EnumWindows/IsWindowVisible to enumerate top-level windows and map them to processes by window handle.

Small UI tips: show PID in a hidden column or tooltip for debugging, disable action buttons when nothing is selected, and provide a Refresh button so users can rebuild the list when windows open/close. This keeps the behavior predictable and robust across different user privileges and OS versions.

This isn't ListView code, but it will help:

While quickly looking into this, I noticed ONE difference between running applications and running processes is that the applications have Window Titles.
There is probably some other quality, but that's the first thing I saw.

So, looping through the processes that have Window Titles will get the applications.

Consider this:

using System;
using System.Diagnostics;
using System.Linq;

namespace DW_405589_CS_CON
{
   class Program
   {
      static void Main(string[] args)
      {
         foreach (Process proc in Process.GetProcesses().Where(p => !string.IsNullOrEmpty(p.MainWindowTitle)))
         {
            Trace.WriteLine(
               string.Format("{0}({1})", proc.MainWindowTitle, proc.ProcessName));
         }
      }
   }
}

Which will show the applications in the output window.

Putting them in a listview would not be difficult.

Next, once you've narrowed down just the ones you need, you can access the methods on each of those apps (like Kill() and Start())

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.