Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 301523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:00:48+00:00 2026-05-12T07:00:48+00:00

I’m looking for a way to detect the # of running processes that has

  • 0

I’m looking for a way to detect the # of running processes that has same process name.

In example, I ran notepad three times.

notepad.exe
notepad.exe
notepad.exe

So it will return 3.

I currently have these code to detect a running process, but not counting its running process quantity.

#include <iostream>
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>

bool IsProcessRunning(const char *ProcessName);

int main()
{
  char *notepadRunning = (IsProcessRunning("notepad.exe")) ? "Yes" : "No";
  std::cout << "Is Notepad running? " << notepadRunning;
  return 0;
}

bool IsProcessRunning(const char *ProcessName)
{
   PROCESSENTRY32 pe32 = { sizeof(PROCESSENTRY32) };
   HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

   if(Process32First(hSnapshot, &pe32))
   {
      do
      {
         if(_tcsicmp(pe32.szExeFile, ProcessName) == 0)
         {
            CloseHandle(hSnapshot);
            return true;
         }
      } while(Process32Next(hSnapshot, &pe32));
   }

   CloseHandle(hSnapshot);
   return false;
} 

Any kind of help would be appreciated 🙂

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:00:49+00:00Added an answer on May 12, 2026 at 7:00 am

    You are using the correct API, namely CreateToolhelp32Snapshot, Process32First and Process32Next. And as you are doing, you should be using the szExeFile member from the struct PROCESSENTRY32.

    You are returning from your function when you find a match currently though. Instead you should be incrementing a counter and NOT returning. And return an int with the process count instead of a bool. Also be sure not to do CloseHandle(hSnapshot); until the end of the function after you have the count.

    Also make sure to first acquire the privilege SeDebugPrivilege before enumerating, that way you will get all processes across all sessions and users.

    To acquire the privilege so you get all sessions:

    acquirePrivilegeByName(SE_DEBUG_NAME);// SeDebugPrivilege
    

    Where acquirePrivilegeByName is defined as:

    BOOL acquirePrivilegeByName(
                                const TCHAR     *szPrivilegeName)
    {
        HANDLE          htoken;
        TOKEN_PRIVILEGES    tkp;
        DWORD           dwerr;
    
        //---------------- adjust process token privileges to grant privilege
        if (szPrivilegeName == NULL)
        {
            SetLastError(ERROR_INVALID_PARAMETER);
            return FALSE;
        }
    
        if (!LookupPrivilegeValue(NULL, szPrivilegeName, &(tkp.Privileges[0].Luid)))
            return FALSE;
    
        tkp.PrivilegeCount = 1;
        tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    
        if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &htoken))
            return FALSE;
    
        if (!AdjustTokenPrivileges(htoken, FALSE, &tkp, 0, NULL, NULL) ||
            GetLastError() != ERROR_SUCCESS)    // may equal ERROR_NOT_ALL_ASSIGNED
        {
            dwerr = GetLastError();
            CloseHandle(htoken);
            SetLastError(dwerr);
            return FALSE;
        }
    
        CloseHandle(htoken);
        SetLastError(ERROR_SUCCESS);
    
        return TRUE;
    } //acquirePrivilegeByName()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.