Using the SAPI object in Inno Setup - inno-setup

I want to use the Windows SAPI COM object to make a sound during installation.
I know that in VBScript they do it like this:
Set oVoice = CreateObject("SAPI.SpVoice")
set oSpFileStream = CreateObject("SAPI.SpFileStream")
oSpFileStream.Open "xxx.wav"
oVoice.SpeakStream oSpFileStream
oSpFileStream.Close
I asked, how to do this in an Inno Setup script.
I'm pretty new to Inno Setup, and still have not learned how to use the CreateOleObject function and so on.
I tried to understand the Inno Setup documentation and it did not help me.
Other answers about using COM objects also did not make me understand this.
Thanks for your help

Use CreateOleObject support function:
var
oVoice, oSpFileStream: Variant;
begin
oVoice := CreateOleObject('SAPI.SpVoice');
oSpFileStream := CreateOleObject('SAPI.SpFileStream');
oSpFileStream.Open('xxx.wav');
oVoice.SpeakStream(oSpFileStream);
end;
See Pascal Scripting: Using COM Automation objects.
For alternate solution, see Playing sound during an Inno Setup install.

Related

Inno Setup: Cannot call "WIZARDISCOMPONENTSELECTED" function during Uninstall

What would cause the message:
Cannot call "WIZARDISCOMPONENTSELECTED" function during Uninstall.
It has to be here:
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usUninstall then
begin
if WizardIsComponentSelected('mycomponent') then
begin
DoSomething(False);
end;
end;
end;
How do you determine if the component was selected at uninstall time? It has to undo some stuff before uninstalled. Typically Inno Setup has ways to get if something was installed or not.
There's no API in Pascal Script to tell in the uninstaller, what tasks were selected when installing. Probably because, there might have been multiple installations, each with different set of tasks. So it would be questionable, what set of tasks the API should report.
What you should (and need) to do is to check the effect of the task. Like checking if a specific file or a specific Registry key exists.
Though note that Tasks parameters still work in the uninstaller sections [UninstallDelete] and [UninstallRun]. So you can make use of them.
See also Inno Setup Uninstall some components only

Inno Setup - How to copy the created setup file

I want to copy the created setup file to a network directory. I think the [Run] section will be the best position to do this, but I cannot not found any possibility to call my copy function. Any idea to this issue?
Also, is it possible to use variables declared in the [setup] section for the copy path?
My procedure will be like this (trying to use the variables):
[Code]
procedure CopyFile();
begin
FileCopy('{OutputDir}/{OutputBaseFilename}',
'V:/Service/Software/ASCDeploy/Prod/Asc.Tools.FileCopy/{OutputBaseFilename}', False);
end;
There's no way to run any code after Inno Setup finishes compiling - At least not in the original Inno Setup.
See also Inno Setup - Post Processing.

Can I put setup command line parameters in a file which is called during installation instead?

After creating my setup.exe I have to pack it for various software deployment tools. Therefore I can't call the setup.exe with parameters, instead I have placed my own parameters in a setup.ini file next to the setup.exe
[Code]
var
MyIniFile: String;
function InitializeSetup(): Boolean;
var
LoadFromIniFile: String;
begin
Result := true;
MyIniFile := ExpandConstant('{srcexe}'); //writes the full path of the setup.exe in "MyIniFile"
MyIniFile := Copy(MyIniFile, 1, Length(MyIniFile) - Length(ExtractFileExt(MyIniFile))) + '.ini'; //changes the ".exe" into ".ini"
if FileExists(MyIniFile) then LoadFromIniFile := MyIniFile; //checks wether there is a ini-file
if LoadFromIniFile <> '' then begin
MyLogFile := GetIniString('Setup', 'Log', MyLogFile , LoadFromIniFile);
ProductName := GetIniString('Setup', 'ProductName', ProductName, LoadFromIniFile);
end;
end;
Now I want to also place the so called "Setup Command Line Parameters" (listed on the Inno Setup Help site) in my ini-file. I think that there is a way for the /Dir="x:\dirname parameter, which I did not figure out yet. But I also want to have the /SILENT parameter in there, do you think there is a way to do this? If yes, how would you do this? If not, can you please give me a hint why not?
So customize your installer for different products, I'd recommend you to use a pre-processor and automatically build the installer for each product (with different "defines"), instead of using an external INI file.
For example to be able to change application name and resulting executable when building the installer, use a script like:
[Setup]
AppName={#AppName}
OutputBaseFilename={#BaseFilename}
Now you can create two different installers automatically using command-line:
ISCC.exe Example1.iss /dAppName=App1 /dBaseFilename=SetupApp1
ISCC.exe Example1.iss /dAppName=App2 /dBaseFilename=SetupApp2
Regarding the implicit silent installation:
There's no API other than the command-line /SILENT switch to trigger silent installation.
But you can create a near-silent installation by disabling most installer pages:
[Setup]
DisableWelcomePage=true
DisableDirPage=true
DisableProgramGroupPage=true
DisableReadyPage=true
DisableFinishedPage=true
Actually the above example disables all default pages. But Inno Setup compiler will ignore the DisableReadyPage=true, if all other previous pages are disabled.
You may want to choose a different page to show instead. For example a Welcome page (by omitting DisableWelcomePage=true, but keeping the DisableReadyPage=true).
If you do not mind about using external files (as you already use an external INI file), you can of course wrap the installer to a batch file and call the installer with the /SILENT switch.

Inno setup : Custom messages

We package few other thirdparty softwares along with our installer,and also install them during
the installation of our product. We install them in silent mode and capture their exit codes,
so sotimes, they get installed successfully and give exitcode as "3010" which is reboot required.
So, in those cases we want to show reboot page at the last but want to give a custom message.
what is the best way to show the custom message on the finish page?
[Messages]
#if FileExists("c:\RebootFile.txt")==0
FinishedRestartLabel=To complete the installation of ConditionalMessageOnWizard, Setup must restart your computer. Would you like to restart now?
#else
FinishedRestartLabel=Reboot Required
#endif
I am using the above code, but i am unable to use the dynamic paths like {sd} or {tmp} for fileexists function.
Can anyone help?
After clarification of your problem, we've found that you actually want to check if a certain file exixts and conditionally change the FinishedLabel caption at runtime.
The #emit, or in short # starting statements are used by preprocessor. And preprocessing runs right before the compilation. It allows you to conditionally modify the script, which is, after this process is done, compiled. So, with your above script you are in fact checking, if the file c:\RebootFile.txt exists on the machine where the setup is being compiled and depending on the result it then chooses value of the FinishedRestartLabel message. But it never compiles both texts into the setup binary.
You can modify the FinishedLabel caption from code e.g. this way. There you can expand constants without any problem:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Code]
function NeedRestart: Boolean;
begin
Result := True;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if not FileExists(ExpandConstant('{sd}\RebootFile.txt')) then
WizardForm.FinishedLabel.Caption := 'RebootFile NOT found. Restart ?'
else
WizardForm.FinishedLabel.Caption := 'RebootFile WAS found. Restart ?';
end;

Is it possible to change the window title bar of your installer using Inno Setup?

Is it possible to change the title bar of your installer using Inno Setup?
By default is:
AppName=My Program
and when you run the setup in the title bar appears:
Setup - My Program
Is it possible to hide the word "Setup"?
Add the following lines to your InnoSetup script file:
[Messages]
// define wizard title and tray status msg
// both are normally defined in innosetup's default.isl (install folder)
SetupAppTitle = Setup YourApplicationShortName
SetupWindowTitle = Setup - YourApplicationName YourApplicationVersion
This will modify the "title bar" and the "app title" in the tray.
I would suggest not modifying the default configuration in /innosetup/default.isl,
like Sertac Akyuz pointed out. Think of this file as fallback config.
If you don't define a setting, then the setting is taken from default.isl.
Just modify your file; not the default settings!
In the InnoSetup installation folder there's a default.isl file, open that file in a text editor, find the SetupWindowTitle entry and change the right side from Setup - %1 to only %1. Also repeat the process for additional languages you use in the setup, you'll find the matching '.isl' files in the 'Languages' folder.
If you want to change the caption of the main form, try this:
[code]
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpWelcome then
WizardForm.Caption := 'Welcome to My Program';
end;
It, unfortunately, will not change the "Setup" caption on the taskbar. Since this is a delphi application, you would need access to the Application global variable to change this effortless, but this object is not exposed to pascal script, and I don't know any way to do it directly. I think you can follow the #satuon advice to change it using windows messages.
A better solution (also if you want to make your iss setup file be correctly compilable on any computer) is to redefine the certain language string in Messages section after the definition of the Languages file.
For example:
[Languages]
Name: de; MessagesFile: compiler:Languages\German.isl
;Name: en; MessagesFile: compiler:Default.isl
[Messages]
WizardReady=I am ready.
Simple no Codes
[Messages]
SetupWindowTitle=Your Programme Name
You should be able to do that using Pascal scripting. Inno Setup allows you to call SendMessage and PostMessage from your Pascal section. Try to use that to send a WM_SETTEXT message to your window.

Resources