QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: hanness on April 10, 2019, 01:25:56 am

Title: Is it possible to determine if QB64 program is run elevated (as admin)?
Post by: hanness on April 10, 2019, 01:25:56 am
I have a QB64 program on Windows that runs a lot of Windows commands via the "SHELL" command. Some of these need to be run with elevated permissions. If I right-click on my QB64 program and choose "Run as administrator" everything works flawlessly, otherwise, it will not.

Is there a way that I can do a check from within a QB64 program to see if the program was run elevated or not? The idea would be that I would display a message to a user if it was not run elevated and then exit the program.

Thanks!
Title: Re: Is it possible to determine if QB64 program is run elevated (as admin)?
Post by: Pete on April 10, 2019, 02:04:26 am
QB64 does support Windows API functions, but you would need to figure out how to address the library, properly. I've only struggled with four or five of those in the past. All successful, but I just don't have a knack for it yet. Anyway, someone else may know that method, or have another way around it.

http://www.qb64.org/wiki/Windows_Libraries

It might be workable with this: https://www.codeproject.com/articles/317695/detecting-if-an-application-is-running-as-an-eleva

Welcome to the forum.

Pete
Title: Re: Is it possible to determine if QB64 program is run elevated (as admin)?
Post by: visionmercer on April 10, 2019, 04:11:30 am
I use this:
Code: QB64: [Select]
  1. cmd$ = ">nul 2>&1 " + CHR$(34) + "%SYSTEMROOT%\system32\cacls.exe" + CHR$(34) + " " + CHR$(34) + "%SYSTEMROOT%\system32\config\system" + CHR$(34)
  2. errorlevel = _SHELLHIDE(cmd$)
  3. IF errorlevel <> 0 THEN
  4.     PRINT "not elevated."
  5.     PRINT "please run as administrator."
  6.     END
  7.     PRINT "elevated."
  8.  
Title: Re: Is it possible to determine if QB64 program is run elevated (as admin)?
Post by: hanness on April 14, 2019, 12:35:07 pm
Thanks very much for the help.