What are SPAWNWND
and NOTIFYWND
parameters in the program path?
What are SPAWNWND
and NOTIFYWND
parameters in the program path?
Inno Setup 6 has a built-in support for non-administrative install mode.
Basically, you can simply set PrivilegesRequiredOverridesAllowed
:
[Setup]
PrivilegesRequiredOverridesAllowed=commandline dialog
The following is my (now obsolete) solution for Inno Setup 5, based on @TLama's answer.
When the setup is started non-elevated, it will request elevation, with some exceptions:
If the user rejects the elevation on a new install, the installer will automatically fall back to "local application data" folder. I.e. C:UsersstandardAppDataLocalAppName
.
Other improvements:
PrivilegesRequired=none
, the installer will write uninstall information to HKLM
, when elevated, not to HKCU
.#define AppId "myapp"
#define AppName "MyApp"
#define InnoSetupReg
"SoftwareMicrosoftWindowsCurrentVersionUninstall" + AppId + "_is1"
#define InnoSetupAppPathReg "Inno Setup: App Path"
[Setup]
AppId={#AppId}
PrivilegesRequired=none
...
[Code]
function IsWinVista: Boolean;
begin
Result := (GetWindowsVersion >= $06000000);
end;
function HaveWriteAccessToApp: Boolean;
var
FileName: string;
begin
FileName := AddBackslash(WizardDirValue) + 'writetest.tmp';
Result := SaveStringToFile(FileName, 'test', False);
if Result then
begin
Log(Format(
'Have write access to the last installation path [%s]', [WizardDirValue]));
DeleteFile(FileName);
end
else
begin
Log(Format('Does not have write access to the last installation path [%s]', [
WizardDirValue]));
end;
end;
procedure ExitProcess(uExitCode: UINT);
external 'ExitProcess@kernel32.dll stdcall';
function ShellExecute(hwnd: HWND; lpOperation: string; lpFile: string;
lpParameters: string; lpDirectory: string; nShowCmd: Integer): THandle;
external 'ShellExecuteW@shell32.dll stdcall';
function Elevate: Boolean;
var
I: Integer;
RetVal: Integer;
Params: string;
S: string;
begin
{ Collect current instance parameters }
for I := 1 to ParamCount do
begin
S := ParamStr(I);
{ Unique log file name for the elevated instance }
if CompareText(Copy(S, 1, 5), '/LOG=') = 0 then
begin
S := S + '-elevated';
end;
{ Do not pass our /SL5 switch }
if CompareText(Copy(S, 1, 5), '/SL5=') <> 0 then
begin
Params := Params + AddQuotes(S) + ' ';
end;
end;
{ ... and add selected language }
Params := Params + '/LANG=' + ActiveLanguage;
Log(Format('Elevating setup with parameters [%s]', [Params]));
RetVal := ShellExecute(0, 'runas', ExpandConstant('{srcexe}'), Params, '', SW_SHOW);
Log(Format('Running elevated setup returned [%d]', [RetVal]));
Result := (RetVal > 32);
{ if elevated executing of this setup succeeded, then... }
if Result then
begin
Log('Elevation succeeded');
{ exit this non-elevated setup instance }
ExitProcess(0);
end
else
begin
Log(Format('Elevation failed [%s]', [SysErrorMessage(RetVal)]));
end;
end;
procedure InitializeWizard;
var
S: string;
Upgrade: Boolean;
begin
Upgrade :=
RegQueryStringValue(HKLM, '{#InnoSetupReg}', '{#InnoSetupAppPathReg}', S) or
RegQueryStringValue(HKCU, '{#InnoSetupReg}', '{#InnoSetupAppPathReg}', S);
{ elevate }
if not IsWinVista then
begin
Log(Format('This version of Windows [%x] does not support elevation', [
GetWindowsVersion]));
end
else
if IsAdminLoggedOn then
begin
Log('Running elevated');
end
else
begin
Log('Running non-elevated');
if Upgrade then
begin
if not HaveWriteAccessToApp then
begin
Elevate;
end;
end
else
begin
if not Elevate then
begin
WizardForm.DirEdit.Text := ExpandConstant('{localappdata}{#AppName}');
Log(Format('Falling back to local application user folder [%s]', [
WizardForm.DirEdit.Text]));
end;
end;
end;
end;
Inno Setup installers require Admin Privileges by default (if not customized by installer creator). UAC popup will be triggered if user did not change UAC settings in Windows.
http://www.jrsoftware.org/ishelp/index.php?topic=setup_privilegesrequired
[Setup]
: PrivilegesRequired
Valid values:
none
, poweruser
, admin
, or lowest
Default value:
admin
Description: The effect of this directive depends on which version of Windows the user is running:
You can try this program Inno Setup Unpacker
http://innounp.sourceforge.net/
It is not official, but it may work with your .exe file and may restore something from it.
Files other than .iss you can get just by installing your exe file.
If IsAdminLoggedOn
returns True
, the installer is already running with Administrator privileges ("elevated").
Note that there's no privileges separation in Windows XP. If the user you are running the installer with is the Administrator, you always have Administrator privileges. There's no UAC prompt in Windows XP.
The only prompt you can get in Windows XP is "Run as" prompt that allows you to run an application/installer as a different user (usually the Administrator).
By using the (undocumented and deprecated) PrivilegesRequired=none
, you actually tell Inno Setup explicitly not to elevate the installer, even when it is started not-elevated. That you usually get the UAC/Run As prompt anyway is solely because of Windows internal heuristics that detects that the .exe
you are starting is an installer and will probably need to be run elevated.
For details, see my question Make Inno Setup installer request privileges elevation only when needed.
Those two parameters are used for communication between the elevated and non elevated parts of the setup for
...AsOriginalUser
functionality, exit codes, etc.You can probably find more details in the Inno source code itself.
Note that these are an implementation detail and you shouldn't rely on them or do anything with the values.