Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Process.GetProcesses()

Process.GetProcesses()

Scheduled Pinned Locked Moved C#
visual-studiodata-structuresjsonquestion
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Seraphin
    wrote on last edited by
    #1

    Process[] procList = Process.GetProcesses(); It seems VS 2005 (maybe 2003 too) is buggy related to this code. If I have opened windows already before I start my application , VS only show 1 of them. But if I activate a window, which isn't listet in the process array, VS finds it immediately. Anybody here with the same experience? Is "EnumWindows" from Win32 API the only solution?

    E 1 Reply Last reply
    0
    • S Seraphin

      Process[] procList = Process.GetProcesses(); It seems VS 2005 (maybe 2003 too) is buggy related to this code. If I have opened windows already before I start my application , VS only show 1 of them. But if I activate a window, which isn't listet in the process array, VS finds it immediately. Anybody here with the same experience? Is "EnumWindows" from Win32 API the only solution?

      E Offline
      E Offline
      Ed Poore
      wrote on last edited by
      #2

      Are you running this from inside the debugger or from within your own application?


      You know you're a Land Rover owner when the best route from point A to point B is through the mud. Ed

      S 1 Reply Last reply
      0
      • E Ed Poore

        Are you running this from inside the debugger or from within your own application?


        You know you're a Land Rover owner when the best route from point A to point B is through the mud. Ed

        S Offline
        S Offline
        Seraphin
        wrote on last edited by
        #3

        Both types, don't work with both ones.

        E 1 Reply Last reply
        0
        • S Seraphin

          Both types, don't work with both ones.

          E Offline
          E Offline
          Ed Poore
          wrote on last edited by
          #4

          What is Process, your variable or a framework class? (Sorry don't have access to my development machine).


          You know you're a Land Rover owner when the best route from point A to point B is through the mud. Ed

          S 1 Reply Last reply
          0
          • E Ed Poore

            What is Process, your variable or a framework class? (Sorry don't have access to my development machine).


            You know you're a Land Rover owner when the best route from point A to point B is through the mud. Ed

            S Offline
            S Offline
            Seraphin
            wrote on last edited by
            #5

            Process is the framework class.

            E 1 Reply Last reply
            0
            • S Seraphin

              Process is the framework class.

              E Offline
              E Offline
              Ed Poore
              wrote on last edited by
              #6

              Using the following code (.NET 2.0):

              foreach (Process proc in System.Diagnostics.Process.GetProcesses())
              {
              Console.WriteLine(proc.ProcessName);
              }

              Creates the following output:

              aswUpdSv
              spoolsv
              CSRSS
              WINLOGON
              MaxBackServiceInt
              Apache
              CTFMON
              firefox
              explorer
              vsmon
              inetinfo
              htpatch
              ApacheMonitor
              rundll32
              SMSS
              LSASS
              mstask
              WinPatrol
              svchost
              SyncServices
              SERVICES
              acrotray
              svchost
              ashDisp
              Apache
              zlclient
              Amoumain
              SciTE
              mdm
              TSVNCache
              WinMgmt
              ashServ
              css
              System
              stisvc
              SharpDevelop
              Idle

              So I'm not sure what yours is doing. (I tried this with C# Script, article here by me). And also created a simple executable and both seemed to run fine. I havn't tried it from within VS (I don't have the full edition, only the Express, but I will try it when I get the chance).


              You know you're a Land Rover owner when the best route from point A to point B is through the mud. Ed

              S 1 Reply Last reply
              0
              • E Ed Poore

                Using the following code (.NET 2.0):

                foreach (Process proc in System.Diagnostics.Process.GetProcesses())
                {
                Console.WriteLine(proc.ProcessName);
                }

                Creates the following output:

                aswUpdSv
                spoolsv
                CSRSS
                WINLOGON
                MaxBackServiceInt
                Apache
                CTFMON
                firefox
                explorer
                vsmon
                inetinfo
                htpatch
                ApacheMonitor
                rundll32
                SMSS
                LSASS
                mstask
                WinPatrol
                svchost
                SyncServices
                SERVICES
                acrotray
                svchost
                ashDisp
                Apache
                zlclient
                Amoumain
                SciTE
                mdm
                TSVNCache
                WinMgmt
                ashServ
                css
                System
                stisvc
                SharpDevelop
                Idle

                So I'm not sure what yours is doing. (I tried this with C# Script, article here by me). And also created a simple executable and both seemed to run fine. I havn't tried it from within VS (I don't have the full edition, only the Express, but I will try it when I get the chance).


                You know you're a Land Rover owner when the best route from point A to point B is through the mud. Ed

                S Offline
                S Offline
                Seraphin
                wrote on last edited by
                #7

                Hello, sorry for my late answer. No, this code show only a single process. Try to open 2 or more SharpDevelop Instances and you'll see that you only get one of them. In the meantime I found a solution. First get the ThreadID with the Win32 API and then get the ProcessByID, this works.

                E 1 Reply Last reply
                0
                • S Seraphin

                  Hello, sorry for my late answer. No, this code show only a single process. Try to open 2 or more SharpDevelop Instances and you'll see that you only get one of them. In the meantime I found a solution. First get the ThreadID with the Win32 API and then get the ProcessByID, this works.

                  E Offline
                  E Offline
                  Ed Poore
                  wrote on last edited by
                  #8

                  Seraphin wrote:

                  Try to open 2 or more SharpDevelop Instances and you'll see that you only get one of them.

                  Nope I get all processes running as listed in the TaskManager :confused:

                  Seraphin wrote:

                  First get the ThreadID with the Win32 API and then get the ProcessByID, this works.

                  Seems a long way around. Try putting the following code:

                  using System;
                  using System.Diagnostics;

                  class ListProcesses
                  {
                      static void Main(string[] args)
                      {
                          foreach (Process proc in Process.GetProcesses())
                          {
                              Console.WriteLine(proc.ProcessName);
                          }
                          Console.Write("Press ENTER to continue...");
                          Console.ReadLine();
                      }
                  }

                  Into a text file, name it something (like listprocesses.cs) then run csc listprocesses.cs to compile it and then run listprocesses.exe. I just had a thought, are you running in a doman because maybe there's some security restriction in place which stops programs accessing other programs.  Just a possibility?


                  You know you're a Land Rover owner when the best route from point A to point B is through the mud. Ed

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups