Mark Williams 12 Posted Wednesday at 10:50 PM Is there a simple way to check if my app is running elevated? I can see a few oldish posts on this on Google, but nothing recent. I was just wondering if newer Delphi has introduced a simple function for it, although I couldn't find anything in help or likely units. Or perhaps there is a new Windows API procedure? Share this post Link to post
Anders Melander 619 Posted Thursday at 02:10 AM 3 hours ago, Mark Williams said: I can see a few oldish posts on this on Google, but nothing recent. I was just wondering if newer Delphi has introduced a simple function for it, although I couldn't find anything in help or likely units. Or perhaps there is a new Windows API procedure? The ones you found probably does something like this, so I guess that's oldish too : // ----------------------------------------------------------------------------- // // RunningAsAdmin // // ----------------------------------------------------------------------------- // Detect if we're running at an elevated security level. // ----------------------------------------------------------------------------- function RunningAsAdmin: boolean; var hToken, hProcess: THandle; pTokenInformation: pointer; ReturnLength: DWord; TokenInformation: TTokenElevation; begin Result := False; hProcess := GetCurrentProcess; try if OpenProcessToken(hProcess, TOKEN_QUERY, hToken) then try FillChar(TokenInformation, SizeOf(TokenInformation), 0); pTokenInformation := @TokenInformation; GetTokenInformation(hToken, TokenElevation, pTokenInformation, SizeOf(TokenInformation), ReturnLength); Result := (TokenInformation.TokenIsElevated <> 0); finally CloseHandle(hToken); end; except // Ignore error - although none of the above should throw an exception... end; end; 1 Share this post Link to post
emailx45 66 Posted Thursday at 02:46 AM (edited) Here by Craig Chapman a code to Create Elevate Level as Admin https://chapmanworld.com/2015/06/08/elevated-privileges-for-delphi-applications/ Here, by Alex a code to create your verification https://stackoverflow.com/questions/923350/delphi-prompt-for-uac-elevation-when-needed Here, by Ruben Bartelink same question - try this https://stackoverflow.com/questions/1220213/detect-if-running-as-administrator-with-or-without-elevated-privileges/4497572#4497572 Edited Thursday at 02:51 AM by emailx45 1 Share this post Link to post
Lars Fosdal 789 Posted Thursday at 12:41 PM If you want it to always run elevated, you can specify that in the manifest. Share this post Link to post
Mark Williams 12 Posted Thursday at 12:49 PM 6 minutes ago, Lars Fosdal said: If you want it to always run elevated, you can specify that in the manifest. No. I just need to know if user has run my app in elevated mode. My App launches Outlook and if one is running elevated and the other isn't then you get an OLE error. I just want to be able to advise user which is doing which so they can correct. Share this post Link to post