Important! This is an automatic machine translated page. If you can read english, you should Click Here to read the original English version of the article.

Get a List of Running Processes in C# Get Seznam tekmovanje v teku proces v C #

The System.Diagnostics namespace contains functions that allow you to manage processes, threads, eventlogs and performance information. System.Diagnostics namespace vsebuje funkcije, ki vam omogočajo upravljanje procesov, niti, eventlogs in informacije o uspešnosti.

The System.Diagnostics.Process object gives you access to functionality enabling you to manage system processes. Predmet System.Diagnostics.Process vam omogoča dostop do funkcij, ki omogočajo, da sistem za upravljanje procesov. We will use this object to get a list of running processes. Bomo uporabili ta namen dobiti seznam tekočih procesov.

Add this line to your using list: Dodaj to postavko, na svoj seznam z uporabo:

using System.Diagnostics; uporabo System.Diagnostics;

Now you can get a list of the processes with the Process.GetProcesses() method, as seen in this example: Sedaj lahko dobite seznam procesov z Process.GetProcesses () metodo, kot je razvidno v tem primeru:

Process[] processlist = Process.GetProcesses(); Process [] processlist = Process.GetProcesses ();

foreach(Process theprocess in processlist){ foreach (Process theprocess v processlist) (
Console.WriteLine(”Process: {0} ID: {1}”, theprocess.ProcessName, theprocess.Id); Console.WriteLine ( "Process: (0) ID: (1)", theprocess.ProcessName, theprocess.Id);
} )

Some interesting properties of the Process object: Nekaj zanimivih lastnosti procesa objekta:

p.StartTime (Shows the time the process started) p.StartTime (Pokaže čas začel proces)
p.TotalProcessorTime (Shows the amount of CPU time the process has taken) p.TotalProcessorTime (Pokaže časa CPU proces je sprejela)
p.Threads ( gives access to the collection of threads in the process) p.Threads (omogoča dostop do zbiranja niti v postopku)

The .NET framework really makes things simple! . NET framework res naredi stvari preprosto!

This article was originally written on 11/23/06 Tagged with: Ta članek je bil prvotno napisan na 11/23/06 Tagged with: Programming Programming

Daily Email Updates Dnevni Email Updates

You can get our how-to articles in your inbox each day for free. Lahko dobite našo kako do člankov v vašo mapo »Prejeto vsak dan brezplačno. Just enter your name and email below: Preprosto vpišite vaše ime in e-pošto spodaj:


Name: Ime:
Email: E-pošta:

Comments (16) Komentarji (16)

  1. Brandon Brandon

    Simple Correction: (at least to fix mine) Simple Popravek: (vsaj, da se določi rudnik)

    Process processlist = Process.GetProcesses(); Process processlist = Process.GetProcesses ();

    should be: bi bilo treba:

    Process[] processlist = Process.GetProcesses(); Process [] processlist = Process.GetProcesses ();

    Using the original posting way gave 'Cannot implicitly convert' errors, due to Process.GetProcesses() returning an array. Uporaba original napotitvi način je dal "Ni mogoče implicitno pretvoriti" napake, zaradi Process.GetProcesses () vrne niz.

    As a side note, make sure to remove and replace the quotes in the Console.Writeline command, if the compiler complains about that statement. Kot neželeni beležko, poskrbite, da odstraniti in zamenjati kotacije v ukaz Console.Writeline, če prevajalnik pritožuje nad to izjavo. The quotes copied as nonstandard quotations on my machine. Navaja kopira kot nestandardne kotacije na svoj stroj.

    Just trying to help others, thanks for the post, I didn't know about System.Diagnostics until stumbling upon this posting. Samo poskušam pomagati drugim, hvala za post, nisem vedel, dokler System.Diagnostics spotike na to objavo.

  2. The Geek Geek

    Brandon, Brandon,

    Thanks for catching that… typing from memory =) Hvala za ulov, ki ... tipkanje iz pomnilnika =)

    I'm not sure why, but wordpress converts the quotes to some other quote value. Ne vem zakaj, ampak wordpress pretvori ponudbe na nekatere druge vrednosti quote. I'll have to look into that. Bom moral pogledati v to.

  3. Syed Syed

    Hi.. Hi .. i want to know which new process the user has requested to open.. hočem vedeti, katere nove proces uporabnika je zaprosila za odprtje .. i want to control the processes or files to be used by user in C#… hočem nadzor procesov ali datoteke, ki jih uporabnik v C # ...

    can anyone give up how to achive this.. lahko kdorkoli dal gor, kako bi to dosegli .. give the code also if u can… dati kodo, tudi če u moči ...

  4. Umit Umit

    Hi. Živjo. I also want to know which you want to know. Prav tako želim vedeti, v katero želite vedeti. Please help me!! Prosim, pomagajte mi! I want to control the processes which one is open or close??? Hočem za nadzor procesov, ki je eden odprt ali blizu??

  5. Khan Khan

    I am creating a process using some arguments and once the process start I wanted to take a look at the arguments. Jaz sem ustvarjanju postopek, ki uporablja nekatere argumente in ko sem hotel začeti postopek, da pogled na argumente. How do I do that? Kako naj naredim to? I have tried using process.StartInfo.Arguments and it didn't work. Sem se potrudil using process.StartInfo.Arguments in to ni delo. Please help!!! Please help!

  6. mukesh Mukesh

    is there any way to track how much time a person is working on a particular file je torej vsekakor za sledenje, koliko časa je oseba, ki dela na določene datoteke

  7. ssp ssp

    Hi, Is there a way to know how much CPU each thread for a process(say, w3wp.exe) uses?? Zdravo, Ali obstaja način, da veš, koliko CPU nit za vsak proces (recimo, w3wp.exe) uporablja? In other words, w3wp process creates N no. Z drugimi besedami, w3wp proces ustvarja N no. of threads and I want to know exactly how much CPU each thread is using for this particular process. za navoje in hočem vedeti točno, koliko CPU vsaka nit uporablja za ta posebni proces.

  8. Eric Eric

    is there any way to spit out the command line arguments that were used to fire the given process? je torej vsekakor Ispljunuti argumente ukazne vrstice, ki so bile uporabljene za požar, ki proces?
    likie for explorer.exe it would show”C:\WINDOWS\Explorer.EXE” and mmc.exe would show ” C:\WINDOWS\system32\perfmon.msc /s” likie za explorer.exe bi show "C: \ WINDOWS \ Explorer.EXE" in mmc.exe bi show "C: \ WINDOWS \ system32 \ perfmon.msc / s"

    I can see these values using SysInternals process explorer so i'm hoping I can get them using .Net somehow. Vidim te vrednosti z uporabo Sysinternals proces raziskovalec tako da sem hoping morem zaslužiti jih uporabljate. Net nekako. CommanArgument doesn't seem to be an available property on the Process class. CommanArgument ne zdi, da bo na voljo lastnine na razred procesa.

  9. Asem Asem

    Its really a great job..I keep on wasting 3 Hrs to search what you guys are done here.. Njena res velik posel .. jaz vztrajati na hiranje 3 Hrs za iskanje kaj si fantje ste tukaj narediti ..
    Thanks a lot.. Hvala veliko ..

    Asem Ibohal Asem Ibohal

  10. Asem Asem

    How can I get these running process and add to a collection using LINQ ? Kako lahko dobim to tekmovanje v teku proces in prispevajo k zbiranju uporabo LINQ?

    Say, u have a class SystemData(double,string,double,double). Reci, u imajo razreda SystemData (double, string, dvojni, dvojno). You can add the Process information using Linq as : Dodate lahko proces informacije z uporabo Linq kot:

    public systemdata(): base() javni systemdata (): base ()
    { (
    //Add data here / / Add podatki tukaj
    string P_NAME; //process name string P_NAME; / / proces name
    double P_ID; //process ID dvojni P_ID; / / proces ID
    double P_MEM; //memory Usages dvojni P_MEM; / / spomin rabe
    double X_axis=1; zakonskih X_axis = 1;

    var procname = from n in Process.GetProcesses() var n = iz procname v Process.GetProcesses ()
    select n; izberite n;
    foreach (var Pname in procname) foreach (var pname v procname)
    { (
    P_ID = Pname.Id; P_ID = Pname.Id;
    P_MEM = Pname.WorkingSet64 / 1024; P_MEM = Pname.WorkingSet64 / 1024;
    P_NAME = Pname.ProcessName; P_NAME = Pname.ProcessName;
    Add(new SystemData(P_ID, P_NAME, P_MEM,X_axis)); Dodaj (novo SystemData (P_ID, P_NAME, P_MEM, X_axis));
    X_axis ++; X_axis + +;
    } )
    } )
    For complete sample, You can mail me at : Za celoten vzorec, lahko mail me na: iamibohal@yahoo.com iamibohal@yahoo.com

  11. Shaaz Shaaz

    This is great. To je super. But I do have one question. Ampak imam eno vprašanje.

    How would I get an event when a process is started or ended? Kako bi jaz dobil dogodek, ko je postopek začel ali se je končalo?

    Basicly, I am trying to make my own taskbar in C#. V bistvu, se potrudim, da bi svoj lasten penzum v C #.

  12. dzar dzar

    how we can selection to choice only proceses running? kako lahko izbor na izbiro samo proceses vožnjo?

  13. ChokoMd ChokoMd

    Process.GetCurrentProcess(); Process.GetCurrentProcess ();

  14. ChokoMd ChokoMd

    *My bad – Process[] processlist = Process.GetProcesses(); * Moja napaka - procesa [] processlist = Process.GetProcesses ();

  15. CodeMunter CodeMunter

    Ok, so we have a list of processes, and I'm particularly interested in the WINWORD one… So how can I turn that into my private Microsoft.Office.Interop.Word.ApplicationClass _Word object so that I can pull its levers n shiz? Ok, tako da imamo seznam procesov, in me še posebej zanima Winword eni ... Torej, kako se lahko obrnem, da v svoj zasebni Microsoft.Office.Interop.Word.ApplicationClass _Word predmet, tako da lahko potegnem svoje vzvode n shiz ?

  16. silverback12 silverback12

    it outputs the result I wanted. real je rezultat sem hotel. but at the end it throws the error vendar na koncu ga vrže napako

    explorer: 2656: Tuesday, October 06, 2009 1:48:15 PM raziskovalec: 2656: Tuesday, October 06, 2009 1:48:15
    svchost: 960: Tuesday, October 06, 2009 1:45:15 PM Svchost: 960: Tuesday, October 06, 2009 1:45:15
    ConsoleApplication1.vshost: 5676: Thursday, October 08, 2009 10:16:22 AM ConsoleApplication1.vshost: 5676: četrtek, October 08, 2009 10:16:22
    smax4pnp: 2916: Tuesday, October 06, 2009 1:48:29 PM smax4pnp: 2916: Tuesday, October 06, 2009 1:48:29
    RunRM: 3860: Tuesday, October 06, 2009 1:48:38 PM RunRM: 3860: Tuesday, October 06, 2009 1:48:38
    Error: System.ComponentModel.Win32Exception: Access is denied Napaka: System.ComponentModel.Win32Exception: Dostop je zavrnjen
    at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 acces na System.Diagnostics.ProcessManager.OpenProcess (Int32 processId, Int32 acces
    s, Boolean throwIfExited) s, Boolean throwIfExited)
    at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfE na System.Diagnostics.Process.GetProcessHandle (Int32 dostop, Boolean throwIfE
    xited) xited)
    at System.Diagnostics.Process.GetProcessTimes() ob System.Diagnostics.Process.GetProcessTimes ()
    at System.Diagnostics.Process.get_StartTime() ob System.Diagnostics.Process.get_StartTime ()
    at ConsoleApplication1.Program.Main(String[] args) in c:\c#\ConsoleApplicatio na ConsoleApplication1.Program.Main (String [] args) in c: \ C # \ ConsoleApplicatio
    n1\ConsoleApplication1\Program.cs:line 20 n1 \ ConsoleApplication1 \ Program.cs: line 20


Leave a Comment Pustite komentar




Leave your Pustite friendly prijazen comment here. comment here.

If you have a computer help question, Če imate računalnik pomagati vprašanje, click here to leave it on the forums kliknite tukaj, da ga pustijo na forumih instead. namesto.

Note: Your comment may not show up immediately on the site. Opomba: Tvoj komentar morda ne pokažejo takoj na mestu.

Our Friends Naši prijatelji
Getting Started Getting Started


About How-To Geek O Kako naj Geek
What Is That Process? Kaj je to proces?
svchost.exe svchost.exe
jusched.exe jusched.exe
dwm.exe dwm.exe
ctfmon.exe Ctfmon.exe
wmpnetwk.exe wmpnetwk.exe
wmpnscfg.exe wmpnscfg.exe
rundll32.exe rundll32.exe
wfcrun32.exe wfcrun32.exe
Ipoint.exe Ipoint.exe
Itype.exe Itype.exe
Wfica32.exe Wfica32.exe
Mobsync.exe Mobsync.exe
conhost.exe conhost.exe
Dpupdchk.exe Dpupdchk.exe Adobe_Updater.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. Copyright © 2006-2009 HowToGeek.com. All Rights Reserved. All Rights Reserved.