get list of pid of all processes running on the system

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • happiness4all
    New Member
    • May 2007
    • 52

    get list of pid of all processes running on the system

    how to get list of pid of all processes running on the system using c++ in windows???
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Try EnumProcess() in psapi.h.

    Comment

    • happiness4all
      New Member
      • May 2007
      • 52

      #3
      Originally posted by weaknessforcats
      Try EnumProcess() in psapi.h.
      its giving error
      process error LNK2019: unresolved external symbol _EnumProcesses@ 12 referenced in function _main

      Comment

      • happiness4all
        New Member
        • May 2007
        • 52

        #4
        Originally posted by happiness4all
        its giving error
        process error LNK2019: unresolved external symbol _EnumProcesses@ 12 referenced in function _main
        [code=cpp]
        include <windows.h>
        #include<psapi. h>
        #include <iostream>
        using namespace std;
        int main() {

        u_long a[100];
        u_long rsize;

        EnumProcesses(a ,sizeof(a),&rsi ze);
        return 0;
        }
        [/code]
        Last edited by weaknessforcats; Jun 21 '07, 04:25 PM. Reason: added code tags

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Originally posted by happiness4all
          Quote:
          Originally Posted by happiness4all
          its giving error
          process error LNK2019: unresolved external symbol _EnumProcesses@ 12 referenced in function _main


          Code: ( cpp )
          include <windows.h>
          #include<psapi. h>
          #include <iostream>
          using namespace std;
          int main() {

          u_long a[100];
          u_long rsize;

          EnumProcesses(a ,sizeof(a),&rsi ze);
          return 0;
          }
          You forgot to add psapi.lib to your build as an additional linker dependency.

          This code compiles and links with no errors on Visual Studio.NET 2005 after I added psapi.lib to the build.

          Comment

          • happiness4all
            New Member
            • May 2007
            • 52

            #6
            Originally posted by weaknessforcats
            You forgot to add psapi.lib to your build as an additional linker dependency.

            This code compiles and links with no errors on Visual Studio.NET 2005 after I added psapi.lib to the build.
            u r rite i also added the lib then it worked fine.
            why do we have to add some libslike wsock32.lib when we use winsock..etc.

            Comment

            • weaknessforcats
              Recognized Expert Expert
              • Mar 2007
              • 9214

              #7
              Originally posted by happiness4all
              why do we have to add some libslike wsock32.lib when we use winsock..etc.
              Libraries are just precompiled code. Otherwise, you would need the source code. So, you use the header provided with the library and you add the library as a linker dependency.

              For example, you can create your own library with youe favorite functions in it and to the same.

              Comment

              Working...