Inno Setup : How to set installer "Run As Administrator"? - inno-setup

In Inno Setup,
[Setup]
PrivilegesRequired=admin
is still can not Run the installer as Administrator, but I need to Launch my Program at last step of Inno Setup.
How can I do to set my Installer can Run as Administrator ?

I have been having this same problem as well, it took me quite a bit of time to figure out that after you have set the PrivilegesRequired=admin you also need to add runascurrentuser to all the Flags under [Run] section.
[Setup]
PrivilegesRequired=admin
[Run]
Filename: "{app}\MyApp.exe"; Description: "{cm:LaunchProgram,MyApp}"; Flags: runascurrentuser nowait postinstall skipifsilent; Check: returnTrue()
Filename: "{app}\MyApp.exe"; Flags: runascurrentuser; Parameters: "-install -svcName ""MyApp"" -svcDesc ""MyApp"" -mainExe ""MyApp.exe"" "; Check: returnFalse()
I know you have probably already figured out the issue considering this question was asked over two years ago but I thought I would answer it anyway for others like myself who found this unanswered question but would have really liked to have seen an answer.

My inno setup script is belowing,
#define MyAppName "MyApp"
#define MyAppExeName "MyApp.exe"
[Setup]
PrivilegesRequired=admin
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: runascurrentuser nowait postinstall skipifsilent

Related

Clarification about using RunOnceId in [UninstallRun] section of Inno Setup script

Here is my [UninstallRun] section:
[UninstallRun]
Filename: {dotnet40}\regasm.exe; Parameters: /u MSAToolsLibrary_x86.dll; WorkingDir: {app}; Flags: runhidden;
Filename: {dotnet4064}\regasm.exe; Parameters: /u MSAToolsLibrary_x64.dll; WorkingDir: {app}; Flags: runhidden; Check: IsWin64;
Filename: {dotnet40}\regasm.exe; Parameters: /u MSAToolsGMailLibrary_86.dll; WorkingDir: {app}\MSAToolsGMailLibrary; Flags: runhidden
Filename: {dotnet4064}\regasm.exe; Parameters: /u MSAToolsGMailLibrary_64.dll; WorkingDir: {app}\MSAToolsGMailLibrary; Flags: runhidden; Check: IsWin64;
When I compile with Inno Setup 6.1.1 I get this warning:
Warning: There are [UninstallRun] section entries without a RunOnceId parameter. By assigning a string to RunOnceId, you can ensure that a particular [UninstallRun] entry will only be executed once during uninstallation. See the "[UninstallRun]" topic in help file for more information.
I have looked up the help for RunOnceId where it states:
Valid only in an [UninstallRun] section. If the same application is installed more than once, "run" entries will be duplicated in the uninstall log file. By assigning a string to RunOnceId, you can ensure that a particular [UninstallRun] entry will only be executed once during uninstallation. For example, if two or more "run" entries in the uninstall log have a RunOnceId setting of "DelService", only the latest entry with a RunOnceId setting of "DelService" will be executed; the rest will be ignored. Note that RunOnceId comparisons are case-sensitive. If you don't assign a string to RunOnceId, the compiler will warn you about this, which can be disabled using MissingRunOnceIdsWarning.
I can see that I can switch off the warning. But I wanted to know if I really needed to use this parameter in my setup because I never have done so until now.
You should use the parameter, as the warning suggests.
If you don't, for every upgrade (unless your installer uninstalls the previous version), a new execution of your [UninstallRun] commands will be queued. So if you install and then upgrade 9 times, all your uninstall commands will be executed 10 times, when uninstalling. Of course, in your case, that only means each your regasm /u command will fail 9 times. Not a big deal, but if user inspects an uninstaller log (in case they have problems), they will see lot of failures, what may mislead them.
Note that you cannot fix this retrospectively. The uninstall commands queued by previous installers will still be executed for each past installation. But again, were it a major problem, you would probably have noticed already.

How to override a third-party installation directory with inno setup

I need to install a thirdparty software embedded in a installer named thirdparty-installer.exe and also install my application Instruct.exe. My application will be at c:\MyAPP folder and all my thirdparty files must be at c:\windows\system32 (all files will be thrown there, in the system32 root). I have done the following:
#define OutputDirectory_MPP "c:\myAPP"
[setup]
DefaultDirName=c:\MyAPP
DisableDirPage=yes
[dirs]
Name: {#OutputDirectory_MPP}; Attribs: system
[files]
Source: "g:\application\Instruct.exe"; DestDir: {#OutputDirectory_MPP}
Source: "g:\applicationr\thirdparty-installer.exe"; DestDir: "{cf}"; Flags: ignoreversion recursesubdirs createallsubdirs promptifolder; Permissions: system-full;
[Run]
Filename: "{cf}\thirdparty-installer.exe"; Flags: shellexec waituntilterminated
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
(...)
My Instruct.exe installs normally, and when it finishes, the thirdparty-installer prompts and show the user the option to change installation directory. Their default is c:\program files\Thirdparty2020\
How can I impose their installation to be on the c:\windows\system32 folder and leave no option to the user? (possibly even coupled with a silent install).

How to open a INI file with Notepad.exe in [Run] section?

In Inno Setup, how can i open an INI file with Notepad.exe using the [Run] section?
This is what i have, but its getting "%1 is not a valid win32 program"...
[Run]
Filename: "{app}\data.ini"; Description: "Check here see data."; Flags: postinstall runascurrentuser skipifsilent unchecked;
What i need is to open that file in user notepad after finishing the installation, if the user checked that checkbox.
Maybe its easier to do with code, but i am not sure how to do it.
Thanks.
Try this:
Filename: "notepad"; Parameters: {app}\data.ini; Description: "Check here see data."; Flags: postinstall runascurrentuser skipifsilent unchecked;

Error running .exe file in Inno setup

I am trying to make my script run this file:
http://www.microsoft.com/en-us/download/details.aspx?id=40779
before/after (doesn't matter) I install my application.
This is my script:
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
; Flags: skipifsilent
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{AEDD3A70-5044-452B-B78D-9CCE4E130654}
AppName=Pong
AppVersion=2.0
;AppVerName=Pong 2.0
AppPublisher=Roymunson_Studios
AppPublisherURL=http://www.example.com/
AppSupportURL=http://www.example.com/
AppUpdatesURL=http://www.example.com/
DefaultDirName={pf}\Pong
DefaultGroupName=Pong
AllowNoIcons=yes
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
[Run]
Filename: "{app}\Installers\NDP451-KB2858728-x86-x64-AllOS-ENU.exe"; StatusMsg: "Installing .NET Framework 4.5.1"
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Files]
Source: "C:\Users\vroy\Desktop\Debug\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{commondesktop}\Pong"; Filename: "{app}\Pong.exe";
However when it tries to compile the .NET 4.5.1 installer file it shows the following error:
"The process cannot access the file because it is being used by another process"
This makes no sense because the .NET 4.5.1 installer is not being used when I am compiling my Inno script.

How to install Microsoft VC++ redistributables silently in Inno Setup?

How to install Microsoft VC++ redistributables silently in Inno Setup? I used the following code, most of the installation part is silent except the installation progress window.
Here is my [Run] section's code:-
[Run]
Filename: "{app}\bin\vcredist_x86.exe"; \
Parameters: "/passive /verysilent /norestart /q:a /c:""VCREDI~3.EXE /q:a /c:""""msiexec /i vcredist.msi /qn"""" """; \
Check: VCRedistNeedsInstall; WorkingDir: {app}\bin;Flags: runminimized nowait; \
StatusMsg: Installing CRT...
For a smooth install, check if it's necessary to install the redistributable. If the installed version is already up to date (quite likely), don't even unpack it.
[Files]
; VC++ redistributable runtime. Extracted by VC2017RedistNeedsInstall(), if needed.
Source: ".\Redist\VC_redist_2017.x64.exe"; DestDir: {tmp}; Flags: dontcopy
[Run]
Filename: "{tmp}\VC_redist_2017.x64.exe"; \
StatusMsg: "{cm:InstallingVC2017redist}"; \
Parameters: "/quiet"; Check: VC2017RedistNeedsInstall; Flags: waituntilterminated
[Code]
function VC2017RedistNeedsInstall: Boolean;
var
Version: String;
begin
if RegQueryStringValue(HKEY_LOCAL_MACHINE,
'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64', 'Version',
Version) then
begin
// Is the installed version at least 14.14 ?
Log('VC Redist Version check : found ' + Version);
Result := (CompareStr(Version, 'v14.14.26429.03')<0);
end
else
begin
// Not even an old version installed
Result := True;
end;
if (Result) then
begin
ExtractTemporaryFile('VC_redist_2017.x64.exe');
end;
end;
Note that the 14.14 redistributable is also suitable for VS2015.
You can add those to the setup script:
[Files]
Source: "vcredist_x86.exe"; DestDir: {tmp}; Flags: deleteafterinstall
[Run]
Filename: {tmp}\vcredist_x86.exe; \
Parameters: "/q /passive /Q:a /c:""msiexec /q /i vcredist.msi"""; \
StatusMsg: "Installing VC++ 2008 Redistributables..."
Note that the run parameters will change slightly, if you are using a different redistributable version from 2008.
I modified the above code as follows. Then I got it worked properly and the entire installation was pretty smooth and silent.
[Run]
Filename: "{app}\bin\vcredist_x86.exe"; \
Parameters: "/q /norestart /q:a /c:""VCREDI~3.EXE /q:a /c:""""msiexec /i vcredist.msi /qn"""" """; \
Check: VCRedistNeedsInstall; WorkingDir: {app}\bin;
Reference Links:
http://www.computerhope.com/cmd.htm
https://web.archive.org/web/20150925001652/http://blogs.msdn.com/b/astebner/archive/2014/03/08/10078468.aspx
Here is my solution:
Filename: "{tmp}\vc_redist.x86.exe"; Parameters: "/q /norestart"; \
Check: VCRedistNeedsInstall; StatusMsg: "Installing VC++ redistributables..."

Resources