Thread: Retrieving a List of Processes

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    11

    Thumbs down Retrieving a List of Processes

    Hi,

    I'm trying to retrive a list of the processes in memory.
    I can use EnumProcesses and Process32First, but this returns
    much more information than I need.

    I want to only list the processes that are being run under my user name and not SYSTEM or LOCAL SERVICE.

    does anyone know how I can do this?

    thank,
    Ryan

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So just step through the information and compare - what's so hard about that?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    11
    Because I don't know if the process that I'm stepping through are User processes or System processes.

    There is nothing that tell you if it is or not.

    Take the taskmgr for example, this will tell you what the processes are, but I have found nothing in the win32 api that can help me determine this.

    Ryan

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Here's a small example I found (google). Don't know if it works or not - it's a direction to search in atleast.
    Code:
    HANDLE         hToken;
    TOKEN_USER     oUser[16];
    DWORD          u32Needed;
    TCHAR          sUserName[256], domainName[256];
    DWORD          userNameSize, domainNameSize;
    SID_NAME_USE   sidType;
    
    ZeroMemory(oUser,sizeof(oUser));
    
    OpenProcessToken(procHandle, TOKEN_QUERY, &hToken);
    GetTokenInformation(hToken, TokenUser, &oUser[0], sizeof(oUser), &u32Needed);
    
    userNameSize = sizeof(sUserName) - 1;
    domainNameSize = sizeof(domainName) - 1;
              
    LookupAccountSid(NULL, oUser[0].User.Sid, sUserName, &userNameSize, domainName, &domainNameSize, &sidType);
    [EDIT] It works. [/EDIT]

    gg
    Last edited by Codeplug; 10-17-2004 at 11:52 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM
  4. Linked list with two class types within template.
    By SilasP in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2002, 06:13 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM