Announcement

Collapse
No announcement yet.

Using correct registry with the local/non-admin user

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using correct registry with the local/non-admin user

    Hi everyone,

    We have an issue where I'm trying to set an .exe default settings to be run in admin mode with some additional compatibility settings configured. Usually we would set it via the following:
    Code:
    -- Run .exe as Admin or Compatibility
    os_name = System.GetOSName();
    -- Display the name of the OS in a dialog.
    --Dialog.Message("Information", "Your operating system is "..os_name..".", MB_OK, MB_ICONINFORMATION);
    
    if (os_name == "Windows 7" or os_name == "Windows 8" or os_name == "Windows 8.1" or os_name == "Windows 10") then
      if (not Registry.DoesKeyExist(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers")) then
        -- create the key for storing the flag
        Registry.CreateKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers");
      end
      -- create AppCompatFlag in HKCU
      Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers", SessionVar.Expand("%AppFolder%\\EXEName.exe" ), "~ RUNASADMIN HIGHDPIAWARE", REG_SZ);
    end
    However, this doesn't get set correctly if the user that runs the installer is a non-admin user due to the permissions requiring an admin to install and therefore the HKEY_CURRENT_USER uses the admin user used to install it rather than the user who will run it.
    I have tried to change the HKEY to HKEY_LOCAL_MACHINE and even HKEY_USERS using the .Defaults folder but those don't seem to help either...

    Thanks in advance!

  • #2
    Make sure that you enabled "Collect launch user information" in the Build Settings. Then, try this:

    Code:
    local sOS_name = System.GetOSName();
    SessionVar.Set("%UserSID%", System.GetUserSID(SessionVar.Expand("%LaunchUserName%")));
    
    if (sOS_name == "Windows 7" or sOS_name == "Windows 8" or sOS_name == "Windows 8.1" or sOS_name == "Windows 10") then
       if (not Registry.DoesKeyExist(HKEY_USERS, SessionVar.Expand("%UserSID%\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"))) then
          Registry.CreateKey(HKEY_USERS, SessionVar.Expand("%UserSID%\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"));
       end
       Registry.SetValue(HKEY_USERS, SessionVar.Expand("%UserSID%\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"), SessionVar.Expand("%AppFolder%\\EXEName.exe"), "~ RUNASADMIN HIGHDPIAWARE", REG_SZ);
    end
    Ulrich

    Comment


    • #3
      Spot on as usual Ulrich, thank you

      Comment

      Working...
      X