I want to be able to set a string array to all the programs running (only the ones visible on the taskbar). Is this possible in C#? Thanks in Advance :D
How to list running programs in C#?
Collapse
X
-
Something like this may do it for you...
Code:Process[] processRunning = Process.GetProcesses(); StringBuilder sbProcesses = new StringBuilder(); foreach (Process currProcess in processRunning) { if (currProcess.MainWindowHandle.ToInt32() > 0) sbProcesses.Append(currProcess.ProcessName + "\n"); } MessageBox.Show(sbProcesses.ToString());
Last edited by bentleyw; Dec 18 '10, 12:50 PM. Reason: Oops, sorry about that. I forgot the line from above. Give this a try. -
Comment
-
-
emm bentleyw, do you know how I can set a combobox to that array? I've tried comboBox1.DataS ource = sbProcesses; but that doesn't work :( Do you know how I can do this? Thanks :DComment
-
Sure. Assuming that the ComboBox is named "cmbProcess es", you could use a list like this:
Code:Process[] processRunning = Process.GetProcesses(); List<string> processList = new List<string>(); foreach (Process currProcess in processRunning) { if (currProcess.MainWindowHandle.ToInt32() > 0) processList.Add(currProcess.ProcessName); } cmbProcesses.DataSource = processList;
Comment
-
Comment