Ah, in that case you could do one of the following:
- Take care of it all during install when the installer does the elevation
- Elevate the app so the UAC pops up. This can be done a few ways:
a) Have your program be able to start with command line params that just starts, performs the registry tweaks then closes down without showing any UI. This allows you to use the same app for elevated registry tweaks rather than two apps as with b) below
b) Have another small app that takes care of your registry tweaks. Call that via elevation from the first to take care of the registry tweaks.
Here’s some code from an old test project of mine (probably needs some prettifying) that will try an elevate.
[code]Public Function RunAs(filename As String, ParamArray Parameters As String) as Integer
'Declares created using https://forum.xojo.com/47389-xojo-ide-reformat-code-script or https://blog./2017/01/22/windows-to-xojo-data-type-conversion/
'See https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx for more error messages and flags
'More info at https://docs.microsoft.com/en-gb/windows/desktop/api/shellapi/ns-shellapi-_shellexecuteinfoa
'I have added all the error messages here so you can add extra functionality if you require it
Const SE_ERR_FNF = 2 'file not found
Const SE_ERR_PNF = 3 'path not found
Const SE_ERR_ACCESSDENIED = 5 'access denied
Const SE_ERR_OOM = 8 'out of memory
Const SE_ERR_SHARE = 26 'Cannot share an open file
Const SE_ERR_ASSOCINCOMPLETE = 27 'File association information not complete
Const SE_ERR_DDETIMEOUT = 28 'DDE operation timed out
Const SE_ERR_DDEFAIL = 29 'DDE operation failed
Const SE_ERR_DDEBUSY = 30 'DDE operation is busy
Const SE_ERR_NOASSOC = 31 'File association not available
Const SE_ERR_DLLNOTFOUND = 32 'Dynamic-link library not found
'flags - See https://docs.microsoft.com/en-gb/windows/desktop/api/shellapi/nf-shellapi-shellexecutea
Const SW_HIDE = 0
Const SW_SHOWNORMAL = 1
Dim ok As Integer
Dim params As String = Join(Parameters, " ")
Soft Declare Function ShellExecute Lib “Shell32” Alias “ShellExecuteW” (hwnd As Integer, lpOperation As WString, lpFile As WString, lpParameters As WString, lpDirectory As WString, nShowCmd As Int32) As Integer
ok = ShellExecute(0, “RunAS”, filename, params, “”, SW_HIDE)
'We could do something fancy here
If ok > 32 Then
'everything worked
system.DebugLog(“Elevation worked!”)
Else
Select Case ok
Case SE_ERR_ACCESSDENIED
'User declined elevation
system.DebugLog(“User declined elevation”)
Else
'Something else went wrong
system.DebugLog(“Uh oh!”)
End Select
End If
'Or we just could just return the result so the caller can handle the error
Return ok
End Function
[/code]