Delphi - Find out if the application has administrator privileges.

Asked

Viewed 798 times

2

Good afternoon, I need to know if an application written in Delphi is running with administrator privileges or not. Does anyone know any way to get that information?

  • Do you have access to the source code ? Do you know what version of Delphi was written ? If the answer to the 2 questions is negative, you want to know if the executable was executed as administrator through the Operating System ?

  • I’m writing the code... kkkkk

  • I need to release a system functionality only when it runs as an administrator.

  • Man, I confess I’ve had to do this before, but I never found a "right" way. Every time I did a treatment to try to do what I needed to do, and if I couldn’t, I took care of the exception. I can suggest a case where I needed to create a registry in windows if you want.

  • That’s exactly what I need, to release a setting that writes to the Windows registry when it has administrator privileges. I am doing it this way, I try to recover what I have in regedit when I open the application and if there is an exception, block the configuration. Is there any other way?

  • 2

    Help? http://stackoverflow.com/questions/6261865/looking-for-delphi-7-code-to-detect-if-a-program-is-started-with-administrator-r

  • It worked!!!! It worked with the external routine Function Isuseranadmin(): BOOL; External shell32; windows. Thank you @Victort.

  • @Victort., Put the link example as a response, just so we don’t lose the content, and can mark the response as valid

  • I’m glad it worked out. Abs

Show 4 more comments

1 answer

3

Windows has a routine that returns if the user has administrator permissions, you can access it through Unit Shellapi by declaring the external routine in the Unit header as follows:

function IsUserAnAdmin(): BOOL; external shell32;
  • But she checks the situation of user and not of process as specified in the question.

  • Yes, from the user who ran the application.

  • If it is executed with the option "run as administrator" the function returns True.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.