We’d like to thank Wayne Golding for offering the following tip. Wayne Golding has been a Xojo developer since 2005. He operates an IT Company Axis Direct Ltd www.axisdirect.nz which primarily develops applications using Xojo that integrate with Xero www.xero.com. Wayneâs hobby is robotics where he uses Xojo to build applications for his Pi2 often implementing IoT for remote control.
Do you need to run a Xojo Application on Windows with Elevated UAC? Here’s Wayne’s trick to achieve that goal.
Launch the executable with this method:
Sub ExecuteWithUAC(Program As String, Args As String) Dim f As FolderItemâ¨ â¨Dim t As TextOutputStreamâ¨ â¨Dim Script As String = "Set objShell = CreateObject(""Shell.Application"")" + EndOfLine _â¨ â¨ + "objShell.ShellExecute ""<Program>"", ""<Args>"", """", ""runas"", 1" + EndOfLine â¨ Dim s As Stringâ¨ â¨ f = GetTemporaryFolderItem â¨ f = GetFolderItem(f.NativePath + ".vbs") â¨ t = TextOutputStream.Create(f) â¨ s = ReplaceAll(Script, "<Program>", program) â¨ s = ReplaceAll(s, "<Args>", Args)â¨ â¨ t.WriteLine sâ¨ t.Close Dim sh As New Shellâ¨ â¨ sh.Mode = 0â¨ â¨ sh.TimeOut = 10000 â¨ â¨ sh.Execute("Wscript.exe " + f.NativePath)â¨ â¨ f.Delete End Sub
This little method writes a visual basic script to launch your program with Elevated Access Rights. It does not bypass the security of Windows, just requests the user to agree/enter administrator credentials. The Program parameter needs to be the nativepath of the executable file. The args parameter needs to be double quoted (“”).
I use this method to launch Console apps to do things like update “protected” registry items and/or install programs.
Download Wayne’s demo for Windows UAC.