Inno Setup Creating registry key for logged in user (not admin user)

蓝咒 提交于 2019-12-28 04:29:05

问题


I'm trying to create an installer using Inno setup when I encounter this problem, everything else is being installed, but the registry keys are not being installed in the current user, I can't find it in the HKEY_CURRENT_USER. But when I try to run the Regedit as Administrator, the registry is installed there. I have UAC turned on and validating with an admin account for the install to run, why is that happening?

Here's my Registry section

[Registry]
Root: HKCU; Subkey:Software; Flags: uninsdeletekey; ValueName:ABS; ValueType:string; ValueData:ABS;
Root: HKCU; Subkey:Software\Microsoft\Office\Word\Addins\ABS.ScriptManager; Flags: uninsdeletekey;
Root: HKCU; Subkey:Software\Microsoft\Office\Word\Addins\ABS.ScriptManager; ValueName:Description; ValueType:string; ValueData:Script Manager; Flags: uninsdeletekey;

Note: I'm running 32 bit Windows 7


回答1:


I do not think you can write explicitly to registry keys of logged in user from Inno Setup. You can write to registry keys of the user which is running the installer only.

You can write to any (or all) user's registry keys via HKEY_USERS, but I do not know, if you can tell, which user is logged in.


But you can execute an external application that writes the registry key as part of the installation using the runasoriginaluser flag or the ExecAsOriginalUser function.

You can use the reg.exe for this:

[Run]
Filename: reg.exe; Parameters: "ADD HKCU\Software\MyProgram /v Foo /t REG_SZ /d Bar"; \
    Flags: runasoriginaluser runhidden

or

procedure CurStepChanged(CurStep: TSetupStep);
var
  Params: string;
  ResultCode: Integer;
begin
  if CurStep = ssPostInstall then
  begin
    Log('Adding registry key for original user');
    Params := 'ADD HKCU\Software\xxxx /v Foo /t REG_SZ /d Bar';
    if ExecAsOriginalUser(
         'reg.exe', Params, '', SW_HIDE, ewWaitUntilTerminated, ResultCode) and
       (ResultCode = 0) then
    begin
      Log('Added registry key for original user');
    end
      else
    begin
      Log('Error adding registry key for original user');
    end;
  end;
end;

Credits for the idea: @Markus




回答2:


From the wording of your question, it sounds like this is because you are "validating with an admin account for the install to run." If this is the case and you are entering a different account (from that which you are logged in with) at the UAC prompt, the current user then actually becomes the Administrator account you just entered at the UAC prompt and not the account you are logged in with. What you may need to do is use the runasoriginaluser function, which will use the logged in user credentials instead of the account you entered at the UAC prompt.




回答3:


in [Run] section with: Filename: reg.exe; Parameters: "IMPORT ..." and flag: runascurrentuser!



来源:https://stackoverflow.com/questions/28824766/inno-setup-creating-registry-key-for-logged-in-user-not-admin-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!