QB64.org Forum
Active Forums => Programs => Topic started by: SpriggsySpriggs on February 06, 2021, 11:48:01 pm
-
The below code uses the standard setup of asking command prompt if the scope of the current session is user or admin. Then, if not admin, prints a statement saying "please run as administrator". Press enter and then the program uses ShellExecute from Shell32 to apply the "runas" verb to COMMAND$(0) (which is the executable's full path). Then you just press yes on the UAC prompt and voila; an elevated program without using PowerShell. I used to use PowerShell to achieve this but of course that is much slower. ShellExecute isn't only limited to this but I figured I'd at least share this bit with y'all before I do more usage and put it in my API collection.
cmd
= ">nul 2>&1 " + Chr$(34) + "%SYSTEMROOT%\system32\cacls.exe" + Chr$(34) + " " + Chr$(34) + "%SYSTEMROOT%\system32\config\system" + Chr$(34) Print "please run as administrator."