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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:07:19+00:00 2026-05-29T09:07:19+00:00

I am using WINAPI for a program that I am writing. The program has

  • 0

I am using WINAPI for a program that I am writing. The program has the ProcessId of another process and needs to get a handle of it (to be able to terminate it later, and also to periodically check if the process is alive and responding by using WaitForSingleObject). When I compile my program (in Embarcadero RAD Studio 2010 C++ Builder), it works well; the program seems to get the handle successfully and generally works as intended. However, if I launch it from the folder as a standalone exe, it seems to fail to get the handle properly. I checked it by comparing (Companion is a HANDLE and Companion_PID is a DWORD):

GetProcessId(Companion)

and

Companion_PID

Where, a few lines earlier, Companion is taken from Companion_PID in the following code:

Companion = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Companion_PID);

And the “GetProcessId(Companion)” results in 0 (which is a good sign that the OpenProcess failed to return a proper handle.

I’m pretty surprised that this code works differently when run from the compiler and as a standalone exe; I’m assuming in the first case the security attributes are inherited from the compiler itself, but I’d like to hear a possibly better explanation for this behaviour from someone more experienced in WINAPI and security attributes in particular.

Small update: yes, like I thought, OpenProcess results in error 0x5 = ERROR_ACCESS_DENIED.

  • 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-29T09:07:20+00:00Added an answer on May 29, 2026 at 9:07 am

    From OpenProcess function page in MSDN:

    To open a handle to another local process and obtain full access
    rights, you must enable the SeDebugPrivilege privilege.

    I believe your IDE (you’re running your application from IDE, not from compiler) has SeDebugPrivilege enabled by default. When you run your application, your IDE (process) is creating a new process which inherits privileges from IDE, including SeDebugPrivilege and that’s the reason why function succeeds when run from IDE.

    Your application should check whether it has SeDebugPrivilege enabled, and if not, enable it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a program in C++ using WINAPI to monitor certain directory for new
How can I attach to another process using WinAPI? I want to read its
I can't seem to get a reliable timestamp using winapi functions. For example: int
I`m writing a chat using WinSock2 and WinAPI functions. And I have a little
I have a question regarding using Semaphores HANDLE WINAPI CreateSemaphore(...); Is there anyway I
I am using CreateProcess to create a cmd.exe process that is passed a parameter
I need to get the up to date memory useage of a program that
I have code that makes a screenshot of the window using winapi. Then I
I'm using WinApi. Is SendMessage/PostMessage a good, thread safe method of communicating with the
The documentation of the ListView control (using WinApi) seem to lack some basic information,

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.