Jump to content
Mike Torrettinni

Is another process running as admin?

Recommended Posts

Is there an option to find out if another process is running 'as admin', with elevated rights?

 

My project doesn't run as admin by default, so WM_COPYDATA doesn't work when the other application (which I have no control over) runs as admin. So I would like to check and if it does, to show message "Other application running with elevated rights, close your project and check 'Run as Administrator' and run again"...

 

I was sure this is quite common task, but search didn't provide anything useful, except for plenty of suggestions on how to find if my own process runs with elevated rights. But I need to know for the other process, application.

 

Delphi 10.2.

 

Share this post


Link to post

Thank you @David Heffernan, I managed to put the check together... but while testing, it became obvious that there are many more things involved with elevated privileges (multiple levels, the current user, the process owner/user...). So, since in 99% cases the cause for my issue will be that the other process is running with higher privileges than mine, I will just assume this is the cause when error occurs and let user run my project as admin. I'm OK with this, for now.

 

Share this post


Link to post
On 3/29/2019 at 2:12 PM, Mike Torrettinni said:

My project doesn't run as admin by default, so WM_COPYDATA doesn't work when the other application (which I have no control over) runs as admin. So I would like to check and if it does, to show message "Other application running with elevated rights, close your project and check 'Run as Administrator' and run again"...

The easiest way to detect this is to simply send the message and handle the case where SendMessage() fails with an ERROR_ACCESS_DENIED error:

 

"When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied)."

Quote

I was sure this is quite common task

It is not, actually.

Quote

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×