On windows, I need users to change a registry setting to run the program properly.
https://github.com/fangq/mcx/blob/etherdome/mcxstudio/mcxgui.pas#L1351-L1376
That section of code modifies HKEY_CURRENT_USER, which does not need admin rights. And the section has commented out logic that accesses HKEY_LOCAL_MACHINE with read-only access, which also does not need admin rights.
So, what exactly is failing? Are you referring to the
TfmMCX.UpdateGPUList() method, which does attempt to modify HKEY_LOCAL_MACHINE (after asking the user)? THAT would need admin rights, yes.
I am wondering if there is a way I can prompt a user to type in admin account and then modify without restarting the program?
You cannot elevate a process once it has started running. Your options in this situation are to either:
1. give your app a UAC manifest that sets the "requestedExecutionLevel" to "requireAdministrator". This will make your entire app run elevated, which is undesirable unless most of its functionality requires admin rights in general.
2. Move the Registry-modifying code into a separate standalone process that you can run when needed using ShellExecute/Ex() with the 'runas' verb (or
CreateProcessElevated()). The code can remain in your same EXE if you give your app an optional command-line parameter that it looks for at startup to know whether to execute the Registry-modifying code or your normal app code.
3. Move the Registry-modifying code into a COM object that you can instantiate when needed using the
COM Elevation Moniker.