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.