How to create a hotkey for desktop icon using Inno Setup - windows

How do I create a shortcut hotkey for an icon in Inno Setup?
The website says add this:
HotKey: ctrl + alt + k
Does anyone have sample code?

The HotKey is an optional parameter for [Icons] section entries, so simply add it to your icon entry e.g. this way:
[Icons]
Name: "{group}\My Program"; Filename: "{app}\MYPROG.EXE"; WorkingDir: "{app}"; \
HotKey: "ctrl+alt+k"

Related

How to handle path with spaces in Inno Setup?

I want to allow paths with spaces (for example program files) when installing my program with Inno Setup. However paths with spaces let my installed service crash.
The Inno Setup file looks like this:
[Setup]
AppName=Demo
DefaultDirName={pf}\demo
[Files]
Source: "bin\nssm.exe"; DestDir: "{app}"
Source: "bin\jdk1.8.0_152\jre\*"; DestDir: "{app}\jre"; Flags: recursesubdirs
Source: "build\libs\demo.jar"; DestDir: "{app}"
[Run]
Filename: "{app}\nssm.exe"; \
Parameters: "install demo ""{app}\jre\bin\java.exe"" -jar ""{app}\demo.jar"""
Filename: "{app}\nssm.exe"; Parameters: "start demo"
"nssm.exe" is a service wrapper to execute a java application as a windows service.
The critical part is this line:
Filename: "{app}\nssm.exe"; \
Parameters: "install demo ""{app}\jre\bin\java.exe"" -jar ""{app}\demo.jar"""
As suggested in this question/answer, I tried to use double double quotes, but this doesn't help, the service is still crashing. If I change DefaultDirName to a path without spaces everything works as expected.
DefaultDirName=c:\demo
How do I have to handle paths with spaces?
The problem was the combination of Inno Setup and nssm, which both are escaping double quotes with double quotes. That makes multiple double quotes necessary.
Solution:
Filename: "{app}\nssm.exe"; Parameters: "install demo ""{app}\jre\bin\java.exe"" -jar """"""{app}\demo.jar"""""""
See nssm documentation section "Quoting issues".

Error with the shortcut of vb script created by inno setup

EDIT: I have made little edit to question, describing cause of problem at last.
I have build a setup using Inno. The main file, from where execution starts, is a vbs file. I have set Inno to make shortcut in desktop with a custom icon. But after installation the shortcut gives vbs error of file missing. If i go to main vbs file and run directly or create another shortcut of that vbs file manually in desktop, I can run that shortcut any number of times. So where is the problem. Is it Inno's problem or some scripting problem.
Here's the vbs script (its aim is to start a batch file but dont show cmd window while opening the batch command)
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "run.bat" & Chr(34), 0
Set WshShell = Nothing
I don't know vbs and this script was lying in the Internet. So if there's some obvious problem with the script, please help me correct it.
The exact error I get is:
Script: C:\Admin\start.vbs
Line: 2
Char: 1
Error: The system cannot find the file specified.
Code: 80070002
Source: (null)
Here's the script I used in Inno
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
[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.)
AppName=Test
AppVersion=1.0
AppVerName=Test 1.0
AppPublisher=USV
DefaultDirName=C:\Test
DisableDirPage=yes
DefaultGroupName=Test
DisableProgramGroupPage=yes
OutputDir=C:\Users\Ashu\Desktop
OutputBaseFilename=Test
SetupIconFile=C:\Test\logo2.ico
Compression=lzma
SolidCompression=yes
; "ArchitecturesAllowed=x64" specifies that Setup cannot run on
; anything but x64.
ArchitecturesAllowed=x64
; "ArchitecturesInstallIn64BitMode=x64" requests that the install be
; done in "64-bit mode" on x64, meaning it should use the native
; 64-bit Program Files directory and the 64-bit view of the registry.
ArchitecturesInstallIn64BitMode=x64
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "C:\Test\start.vbs"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Test\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{group}\Test"; Filename: "{app}\start.vbs"; IconFilename: {app}\logo2.ico;
Name: "{group}\{cm:UninstallProgram,Test}"; Filename: "{uninstallexe}"; IconFilename: {app}\logo2.ico;
Name: "{commondesktop}\Test"; Filename: "{app}\start.vbs"; Tasks: desktopicon; IconFilename: {app}\logo2.ico;
[Run]
Filename: "{app}\importstarter.bat";
Filename: "{app}\start.vbs"; Description: "{cm:LaunchProgram,Test}"; Flags: shellexec postinstall skipifsilent
EDIT:
I have updated script that closely resembles the problem. Cause for the problem is in shortcut property, target property is set but start in property is set blank. Correcting it to desired directory solves the problem. Program runs in first attempt because setup directly runs from the main file instead of the shortcut. So this must be a problem of Inno Script.
Your problem is caused by a lack of specific working/current paths and the use of relative paths.
When the vbs file is run, the working/current directory would be that of the installer, c:\Windows\, j:\MyData\, etc. When it tries to run run.bat, it can't find it in the current directory, resulting in the "The system cannot find the file specified." error from the script engine.
The best way to fix this is to force the current directory of the running script to the folder containing it.
(I don't know how to do this off hand)
Alternatively, you can set the current directory on the shortcuts and the [Run] entry:
[Icons]
Name: "{group}\Test"; Filename: "{app}\start.vbs"; IconFilename: {app}\logo2.ico; WorkingDir: "{app}";
Name: "{group}\{cm:UninstallProgram,Test}"; Filename: "{uninstallexe}"; IconFilename: {app}\logo2.ico;
Name: "{commondesktop}\Test"; Filename: "{app}\start.vbs"; Tasks: desktopicon; IconFilename: {app}\logo2.ico; WorkingDir: "{app}";
[Run]
Filename: "{app}\importstarter.bat"; WorkingDir: "{app}";
Filename: "{app}\start.vbs"; WorkingDir: "{app}"; Description: "{cm:LaunchProgram,Test}"; Flags: shellexec postinstall skipifsilent
You can also put this at the top of the batch files so they don't need a specific current directory:
cd /d %~dp0
Note that recent (since 2010) versions of Inno Setup force a working directory to be set to protect against this error.
You need to specify full path and lose the last pointless line.
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "c:\somefolder\run.bat" & Chr(34), 0
Thanks everyone for your concern. The issue was with Inno Setup. I updated it to newer version and the problem was gone without making any changes to the script.
The problem was caused since the shortcut does not contain any starting point folder (thanks #Noodles). So it was unable to find file in the default directory of cmd.

running InstallUtil {app}/file.exe in inno setup

I want to copy service files to {app} directory and then use this as a parameter in InstallUtil.exe.
Here's some part of my code :
[Files]
Source: WCFService.exe; DestDir: {app}
Source: WCFService.exe.config; DestDir: {app}
[Run]
Filename: {dotnet40}\InstallUtil.exe; Parameters: {app}\WCFService.exe
This code doesn't work (but the files are copied into {app} directory correctly). However, if I use something like this :
[Files]
Source: WCFService.exe; DestDir: {src}
Source: WCFService.exe.config; DestDir: {src}
[Run]
Filename: {dotnet40}\InstallUtil.exe; Parameters: WCFService.exe
it works correctly. Does anyone know what's going on?
I have to use inno setup.
In this case you could try to set WorkingDir parameter to {app} in the [Run] section.
Like this:
[Run]
Filename: "{dotnet40}\InstallUtil.exe"; WorkingDir: "{app}"; Parameters: "WCFService.exe"
{app} may contain spaces, and so must be properly quoted when using it on command lines:
[Run]
Filename: {dotnet40}\InstallUtil.exe; Parameters: """{app}\WCFService.exe"""
The outermost set of quotes is for Inno itself; each pair of doubled quotes within that will end up putting a single quote on the command line.

Permanent customized folder icons with InnoSetup in any computer

I have modified some folder icons and I am including these folders in my InnoSetup installation. The problem is that once my program is installed, my customized folder icons are gone and what I see is just the oldfashioned "yellow" Windows folder icons.
EDIT
The answer was provided by the user TLama. It worked in my computer at first. I had some problems with different Windows versions at different computers. I will write now my working code after having tried sucessfully in several computer systems.
Icons used:
Ico1.ico
Ico2.ico
Ico3.ico
Modified folder icons:
c:\FDR1
c:\FDR2\FDR3
Step 1:
I have used the software "Folder icon changer" to have my icon in place for the three folders I wanted changed. You may use any other free software too. After execution, a desktop.ini appeared in each of the newly changed icon folders. For instance, the FDR1 has the content:
[.Shellclassinfo]
Iconfile=F:\Resource\Icons\Ico1.ico
Iconindex= 0
Step 2:
I have then erased the path above and saved "Ico1.ico" into the directory "c:\FDR1" I had just modified :
[.Shellclassinfo]
Iconfile=Ico1.ico
Iconindex= 0
I did the same for the Ico2.ico (inside the FDR2) and the Ico3.ico (inside the FDR3). The "Icon1, 2 and 3" and "desktop.ini" file attributes were all set to hidden. But, it is important NOT to set the icon properties to "read only".
Step 3:
Inside Inno repeat TLama's suggestion.
#define OutputDirectory_1 "c:\FDR1"
#define OutputDirectory_2 "c:\FDR2"
#define OutputDirectory_3 "c:\FDR2\FDR3"
[Dirs]
Name: {#OutputDirectory_1}; Attribs: system
Name: {#OutputDirectory_2}; Attribs: system
Name: {#OutputDirectory_3}; Attribs: system
[Files]
Source: "c:\FDR1\Ico1.ico"; DestDir: {#OutputDirectory_1}; Attribs: hidden system
Source: "c:\FDR2\Ico2.ico"; DestDir: {#OutputDirectory_2}; Attribs: hidden system
Source: "c:\FDR2\FDR3\Ico3.ico"; DestDir: {#OutputDirectory_3}; Attribs: hidden system
Step 4:
Compile !
Now, your folder icons will permanently work in any computer and system !!
Your target folder should have either read only or system attribute configured. To create such folder you can use, like Miral mentioned, [Dirs] section and its attributes. This will have an advantage, that after you run the installation process, InnoSetup automatically notifies Shell about changes, so the folder icon will be changed without an extra notification function call.
; this is a defined preprocessor variable used to simplify the script
; management; this variable contains the path, where the icon will be
; applied (it's used twice in a script, so it's easier to manage that
; from one place)
#define OutputDirectory "d:\TargetDirectory"
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
OutputDir=userdocs:Inno Setup Examples Output
[Files]
; here you need to use "hidden" and "system" values in Attribs parameter
; to include into the Desktop.ini file hidden and system file attributes
Source: "Desktop.ini"; DestDir: {#OutputDirectory}; Attribs: hidden system
[Dirs]
; here you need to use either "readonly" or "system" value in Attribs parameter
; to setup to the output directory read only or system file directory attribute
Name: {#OutputDirectory}; Attribs: readonly
Important:
Don't forget that you have to compile the script using CTRL + F9 before running, whenever you change the content of your input Desktop.ini file as well as when you change the value of the preprocessor path variable (I've been missing this few times and then wondering about the setup package content).
In order to activate custom folder icons you have to programmatically set the "read-only" attribute of the folder containing the desktop.ini file. (You can't do this from Explorer, but you can via the command line and from Inno.)
[Dirs]
Name: {app}; Attribs: readonly
Note that the path inside the desktop.ini file must be valid on the user's filesystem; you may want to use an [Ini] entry to create or modify this file to suit the installation path.
(This doesn't actually make the folder read-only -- this attribute is treated differently on folders by Windows because only files can meaningfully be read-only.)

Inno Setup if and language

I wanted to know how to control the language of inno setup, I would like that when the user selects the English inno setup after installation eliminates the Italian language files, but if the user selects the Italian language, I would like that after the installation would remove the language file English. I tried this code but does not work:
[InstallDelete]
#if {language} = "english"
Type: files; Name: "{commondesktop}\english.txt"
#if {language} = "italian"
Type: files; Name: "{commondesktop}\italian.txt"
#endif
Thanks.
Sorry for my English.
Directives are evaluated at compile time, and in any case [InstallDelete] section is processed at the beginning of the setup. The easiest approach for your case, I believe, is to not install the file in the first place if the user has not chosen the corresponding setup language:
[Languages]
Name: "en"; MessagesFile: "compiler:Default.isl"
Name: "it"; MessagesFile: "compiler:Languages\Italian.isl"
[Files]
Source: "english.txt"; DestDir: "{commondesktop}"; Languages: en;
Source: "italian.txt"; DestDir: "{commondesktop}"; Languages: it;
If I have somehow misunderstood the question, you can use the DeleteFile support function in code to delete a file, for instance in a CurStepChanged procedure while CurStep is 'ssDone' or 'ssPostInstall'.

Resources