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 7076547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:18:41+00:00 2026-05-28T06:18:41+00:00

I read a couple of posts on how to check if a process has

  • 0

I read a couple of posts on how to check if a process has exited from a different process (I realize some people get hung up on semantics here, but just humor me) and I tried to implement it but am running into the error code 5 (“ERROR_ACCESS_DENIED”) all over the place.

Here is what I do.

1) Process 1 (P1) launches process 2 and writes to a shared memory location its own PID.

2) Process 2 (P2) reads the PID from shared memory

3) P2 calls OpenProcess(…) with P1’s PID to save a handle that it can check later.

4) P2 calls GetExitCodeProcess(…) with P1’s PID repeatedly and checks for a STILL_ACTIVE code.

In the above method, I keep getting the ACCESS_DENIED error on GetExitCodeProcess. I’ve tried modifying P2’s privileges by using the below code from MSDN’s docs:

HANDLE proc_h = OpenProcess(SYNCHRONIZE, FALSE, GetCurrentProcessId());
HANDLE hToken;
OpenProcessToken(proc_h, TOKEN_ADJUST_PRIVILEGES, &hToken);

LookupPrivilegeValue(NULL, lpszPrivilege, &luid );

tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Enable the privilege
AdjustTokenPrivileges(hToken, 
                      FALSE, 
                      &tp, 
                      sizeof(TOKEN_PRIVILEGES), 
                      (PTOKEN_PRIVILEGES) NULL, 
                      (PDWORD) NULL);

But I keep getting the ACCESS_DENIED error on the call to OpenProcessToken(…) method. So does this indicate some sort of system level hurdle? I do have admin rights on my machine and I’m running XP.

Thanks in advance for any help.

  • 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-28T06:18:42+00:00Added an answer on May 28, 2026 at 6:18 am

    The handle passed to GetExitCodeProcess requires PROCESS_QUERY_INFORMATION access right.
    The following works fine:

    int main(int a_argc, char** a_argv)
    {
        int pid = atoi(*(a_argv + 1));
    
        HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
    
        if (NULL != h)
        {
            Sleep(2000);
            DWORD exit_code;
            if (FALSE == GetExitCodeProcess(h, &exit_code))
            {
                std::cerr << "GetExitCodeProcess() failure: " <<
                    GetLastError() << "\n";
            }
            else if (STILL_ACTIVE == exit_code)
            {
                std::cout << "Still running\n";
            }
            else
            {
                std::cout << "exit code=" << exit_code << "\n";
            }
        }
        else
        {
            std::cerr << "OpenProcess() failure: " << GetLastError() << "\n";
        }
    
        return 0;
    }
    

    Instead of polling on GetExitCodeProcess open the handle with SYNCHRONIZE and wait for it to exit:

    int main(int a_argc, char** a_argv)
    {
        int pid = atoi(*(a_argv + 1));
    
        HANDLE h = OpenProcess(SYNCHRONIZE | PROCESS_QUERY_INFORMATION, FALSE, pid);
    
        if (NULL != h)
        {
            WaitForSingleObject(h, 5000); // Change to 'INFINITE' wait if req'd
            DWORD exit_code;
            if (FALSE == GetExitCodeProcess(h, &exit_code))
            {
                std::cerr << "GetExitCodeProcess() failure: " <<
                    GetLastError() << "\n";
            }
            else if (STILL_ACTIVE == exit_code)
            {
                std::cout << "Still running\n";
            }
            else
            {
                std::cout << "exit code=" << exit_code << "\n";
            }
        }
        else
        {
            std::cerr << "OpenProcess() failure: " << GetLastError() << "\n";
        }
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read a couple of posts on this issue but still can't seem to
Hallo, Recently I have read a couple of posts on varous sites and blogs
I read a couple posts saying that Google does not offer any way to
I have read a couple of posts on this topic, but neither addresses my
I've read a couple of the other posts on this issue, but seemed to
I notice this has caused confusion for several people, but after reading a couple
I have read a few posts about people putting in either their own icons
I have read a couple of posts for instance... http://blogs.msdn.com/b/adamroot/archive/2009/06/17/source-server-and-symbol-server-features-in-team-foundation-server-2010-beta-1.aspx http://blogs.msdn.com/b/jimlamb/archive/2009/06/15/symbol-and-source-server-in-tfs-2010.aspx From what I
I've seen a couple posts about this issue, but so far nothing has seemed
I've read a couple of posts on SignalR and thought for a fun test

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.