PROKA Posted March 29, 2004 Posted March 29, 2004 I need a method to get all the running applications on my computer ( similar with the "Applications" ln the "Task Manager" ) Quote Development & Research Department @ Elven Soft
Administrators PlausiblyDamp Posted March 29, 2004 Administrators Posted March 29, 2004 Dim progs() As Process progs = System.Diagnostics.Process.GetProcesses Dim p As Process For Each p In progs ListBox1.Items.Add(p.ProcessName) Next Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
PROKA Posted March 29, 2004 Author Posted March 29, 2004 what I really need is not a list of processes running, but a list of applications running ;) press Ctrl-Alt-Del and see the difference between Processes and Applications . I need to know what documents are open with what programs . For example : My Document1.doc - Ms Word, Metallica - Fade to black - Winamp, My doc2.rtf - Ms Word, Question.txt - Notepad, Xtreme .NET Talk - List of applications running - Microsoft Internet Explorer :) etc Quote Development & Research Department @ Elven Soft
Administrators PlausiblyDamp Posted March 29, 2004 Administrators Posted March 29, 2004 Dim progs() As Process progs = System.Diagnostics.Process.GetProcesses Dim p As Process For Each p In progs Dim title As String = p.MainWindowTitle If title <> String.Empty Then ListBox1.Items.Add(title) End If Next then Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Menge Posted March 29, 2004 Posted March 29, 2004 though that code will only show the processes that have a mainwindow attached to them. items like Explorer and second and on instances of IE won't show. i recommend that you use the EnumWindows API call in user32.dll and then filter the iwndows that you want. Declarations that you'll need for proper filtering // delegate declaration used for EnumWindows() callback function private delegate bool EnumWindowsProc(IntPtr hWnd, int lParam); // importing the function [DllImport("user32.dll")] private static extern int EnumWindows( EnumWindowsProc ewp, // Callback function int lParam // Optional parameter to pass to the callback ); // this function helps filter out the Program Manager [DllImport("user32.dll")] private static extern int GetClassName( IntPtr hWnd, // handle to the window to get the class System.Text.StringBuilder lpClassName, // StringBuilder where to store the classname int nMaxCount // Max count of characters to retrieve from the classname ); // this function is to retrieve the window's title [DllImport("User32.Dll")]private static extern void GetWindowText( IntPtr h, // Handle to the window to get the text from System.Text.StringBuilder s, // StringBuilder where to store the title int nMaxCount // Max count of characters to retrieve from the name ); // find out if window is visible or hidden [DllImport("user32.dll")]private static extern bool IsWindowVisible( IntPtr hWnd // Handle to the window ); Calling the function EnumWindows(new EnumWindowsProc(WindowReceived), 0); The filtering being done by the callback // the EnumWindows filtering the selected windows private bool WindowReceived(IntPtr hWnd, int lParam) { System.Text.StringBuilder class=new System.Text.StringBuilder(256); GetClassName(hWnd, class, 256); string WndClass=class.ToString().Trim(); System.Text.StringBuilder title=new System.Text.StringBuilder(256); GetWindowText(hWnd, title, 256); string WndTitle=title.ToString().Trim(); RECT r; GetWindowRect(hWnd, out r); if(r.right-r.left<=0 || r.bottom-r.top<=0) return true; if(WndTitle!="" && IsWindowVisible(hWnd) && WndClass!="Progman") { // put valid window listing code here // always return true on this callback. // return false only if you want to stop enumerating } return true; } i think that's about it. simple huh? :P Quote Menge
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.