Author Topic: Is it possible to determine if QB64 program is run elevated (as admin)?  (Read 3125 times)

0 Members and 1 Guest are viewing this topic.

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
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!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Marked as best answer by hanness on April 14, 2019, 08:35:25 am

Offline visionmercer

  • Newbie
  • Posts: 8
    • View Profile
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.  

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Thanks very much for the help.