Connecting Tech Pros Worldwide Help | Site Map

Listing applications

Newbie
 
Join Date: Nov 2008
Posts: 3
#1: Nov 15 '08
How would you make a list of running applications in c#
joedeene's Avatar
Site Addict
 
Join Date: Jul 2008
Location: US of A
Posts: 587
#2: Nov 15 '08

re: Listing applications


You can use the Process Class to get a list of running processes? Here's a sample code that adds the process name to a listbox.

Expand|Select|Wrap|Line Numbers
  1.  private void button1_Click(object sender, EventArgs e)
  2.         {
  3.          foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcesses())
  4.          {
  5.              listBox1.Items.Add(proc.ProcessName);
  6.  
  7.          }
  8.         }
Does something like that work for you?

joedeene
Newbie
 
Join Date: Nov 2008
Posts: 3
#3: Nov 15 '08

re: Listing applications


Yeah that works but what i really need is a list of running applications e.x. not notepad.exe but the file that goes with notepad.exe
joedeene's Avatar
Site Addict
 
Join Date: Jul 2008
Location: US of A
Posts: 587
#4: Nov 15 '08

re: Listing applications


...Could you explain? You want the file with notepad.exe? Do you mean the StartUp path, and location, of the process? Or the file opened with notepad?

joedeene
Newbie
 
Join Date: Nov 2008
Posts: 3
#5: Nov 16 '08

re: Listing applications


ok...my main goal with this is to have a user type in an application(or selecet one from a list) and find the owner or user name of the person/thing useing that application. For example someone types in "C:\Test.txt" and it would find who is useing that file
balabaster's Avatar
Moderator
 
Join Date: Mar 2007
Location: Canada
Posts: 757
#6: Nov 16 '08

re: Listing applications


I'd hit CTRL+ALT+DEL and look at task manager...

Of course, if I wanted to do it programmatically I'd probably reference WMI and "Select * From Win32_Process"

WMI is extremely powerful for accessing and programmatically controlling administrative tasks.

It should also give you access to the list of currently active processes and which user/principal is in control of that process. I'm not sure however if it'll tell you which file is being used by which.

You can also find this information administratively in Computer Management/Shared Files

I've never had to programmatically do this though - I'll do some more digging and figure out what I can find...
Reply