Uninstaller trouble with standard Windows user

半腔热情 提交于 2020-02-22 19:07:12

问题


I am wondering if I am encountering the same bug with Windows 10 discussed in this post.

I am having a problem with uninstalling a program installed by a standard user without elevation.

I am using INNO Setup, so I have PrivilegesRequired=lowest, and INNO does not prompt for elevated privilege, and installs for the current user, and creates an uninstaller, e.g. uninst000.exe, in my application folder, and I have INNO put an icon for the uninstaller in a Start Menu group for my app (all this done for the current user). INNO also adds an item in the Settings/Apps & Features applet of Windows 10 (this is where the problem comes in).

If the uninstaller is launched from the Start menu icon, there is no prompt for elevated privilege, and my app uninstalls with no trouble.

If the uninstaller is launched from the Apps & Features, a prompt for elevated privilege appears, and if admin credentials are entered (which they must be), the app is not uninstalled correctly. Some things are uninstalled, but not everything. App files are removed, and the start menu group is removed, but additional cleanup actions in INNO's [UninstallRun] section are not getting done. Also, the Uninstall item is not removed from the list in Apps & Features.

So my question is, is this caused by the Windows 10 bug mentioned in the earlier post?


回答1:


I have followed the suggestion of @MartinPrikryl to have the uninstaller (i.e. InitializeUninstall) check the privilege it is running under, and check if the uninstall key is in HKLM or HKCU area of registry. So far my testing shows this works well.

function IsRegularUser(): Boolean;
begin
    Result := not (IsAdminLoggedOn or IsPowerUserLoggedOn);
end;

function WasInstalledAsStandardUser(): Boolean; //return true if uninstall key is in Current User area of registry
var
    sUnInstPath: String;
    sUnInstallString: String;
begin
    sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppName")}_is1');
    sUnInstallString := '';
    Result := True;
    { only one of these keys should be present, but if both are, return True for nonadmin }
    if RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then Result:=False;
    if RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString) then Result:=True;
end;

function InitializeUninstall: Boolean;
begin
    if WasInstalledAsStandardUser() and (Not IsRegularUser) then begin
        MsgBox( MyApp was installed with standard user rights, so it must be uninstalled with stardard user rights.'#13'  So use Start/All Programs/MyApp/Uninstall.', mbInformation, MB_OK);
        Result:=False; exit;
    end;
    Result := True;
end;


来源:https://stackoverflow.com/questions/47963173/uninstaller-trouble-with-standard-windows-user

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