Use innosetup script to delete previously installed application folder - inno-setup

I am deleting the previous application using the script which inturn calls my .net app. All i want is to actually delete the folder(entire app1) from start menu (start->Programs->app1->uninstall app1)?
Thanks
Gauls

If you just want to delete the "uninstall app1" icon from the Start menu, the following should work:
[InstallDelete]
Type: files; Name: "{group}\uninstall app1"
If you want to remove the entire program group from the start menu, use the following:
[InstallDelete]
Type: filesandordirs; Name: "{group}"
This assumes that your Inno Setup script Start menu folder name is the same as the previous "app1" application.

None of those worked for me, after work-around, here is my solution;
in [Setup]
//Delete old entry folder from start menu
procedure DeleteOldStartMenuEntry;
var
entry: String;
begin
//Replace "Diviner" with desired folder name
entry := ExpandConstant('{commonprograms}') + '\Diviner\';
if DirExists(entry) then begin
DelTree(entry, true, true, true);
end
end;
Inside InitializeSetup call your procedure :
function InitializeSetup: Boolean;
var:
....
begin
....
DeleteOldStartMenuEntry;
....
end;

Thanks Craig my new app doesn't have the same name (app2) following worked for me
[InstallDelete]
Type: filesandordirs; Name: {commonprograms}\app1

Related

Inno setup can not create desktop icon in windows 10

I have setup file for inno setup of latest version. It compiles and works great from windows xp to windows 8, but in windows 10 it fails on the moment when it creates desktop icon with next error:
IPersistFile::Save failed; code 0x80070002
This is how I create icon in setup file:
[Icons]
Name: "{userdesktop}\Forex Tester 4"; Filename: "{app}\ForexTester4.exe"; Tasks: desktopicon
Part of the installation log file:
2019-02-01 12:50:46.376 -- Icon entry --
2019-02-01 12:50:46.376 Dest filename: C:\Users\Mike\Desktop\Forex Tester 4.lnk
2019-02-01 12:50:46.376 Creating the icon.
2019-02-01 12:50:46.376 Exception message:
2019-02-01 12:50:46.376 Message box (OK):
IPersistFile::Save failed; code 0x80070002.
The system cannot find the file specified.
2019-02-01 12:50:59.066 User chose OK.
This folder exists and I can create files there manually. But inno setup fails to do this... All other icons except desktop one were created without problems.
Any ideas?
I had the same error on Windows 7 and Windows 10 because I was trying to create shortcut to file that didn't exist yet.
[Icons]
; Create icons for the app
Name: "{group}\{#AppName}"; \
Filename: "{app}\{#AppName}.lnk"; \
BeforeInstall: CreateAppRunLink();
Name: "{commondesktop}\{#AppName}"; \
Filename: "{app}\{#AppName}.lnk"; \
Tasks: desktopicon;
So I had to make sure that file "{app}{#AppName}.lnk" exists prior to creating the Icon:
This goes to [Code] section:
procedure CreateAppRunLink();
var
Filename: string;
Description: string;
ShortcutTo: string;
Parameters: string;
WorkingDir: string;
IconFilename: string;
begin
Filename := ExpandConstant('{app}\MyApp.lnk');
Description := 'Description';
ShortcutTo := 'Full path to file that will be run (MyApp.exe)';
Parameters := 'parameters if any';
WorkingDir := ExpandConstant('{app}');
IconFilename := ExpandConstant('{app}') + '\icon.ico';
CreateShellLink(Filename, Description, ShortcutTo, Parameters, WorkingDir,
IconFilename, 0, SW_HIDE);
end;
CreateAppRunLink will will be called after extracting any files from [Files] section which will make sure that our file is in place.
Hope that'll help.
It could be a relatively new (since version 1709) Windows 10 feature called Controlled folder access. See Allow a blocked app in Windows Security for instructions on turning it on or off.

Remove folder specified by user at install time in Inno Setup Uninstaller

I have a setup script which allows the user to specify a relative path where the application will save some files and folders. The path will be saved to a config.ini file. Till then everything works as expected.
Now I want the uninstaller to perform a removing of all content under the specified path. In my installer script I have a variable
var DataPath : String;
which holds the path.
To perform the removing I added the following lines of code (as mentioned on their website) to my script:
[UninstallDelete]
Type: filesandordirs; Name: DataPath
Unfortunately this doesn't work. Does anyone know how to do this?
My [INI] sections look like the following:
[INI]
Filename: "{app}\config.ini"; Section: "connection = standard"; \
Key: datapath; String: {code:GetDataPath}
Use {code:GetDataPath} in the [UninstallDelete], the same way you use it in the [INI] section:
[UninstallDelete]
Type: filesandordirs; Name: {code:GetDataPath}

Uninstall everything even "newly created file by Application" using inno setup

I create installer for My Application "Demo"(.Net app) using INNO Setup. Install and Uninstall works smooth when without launching our application.
Uninstall not clean everything if Application is launch. Because my application update existing files and creating some files during Launch.
So how can we clean everything after launch also?
My script code available # script code
Thanks in advance
You can achieve that in 2 ways.
1st simple, but User will not be informed about deleting new/changed/additional files:
[UninstallDelete]
Type: filesandordirs; Name: "{app}"
{app} expands as a full path to you Application.
By default (basing on your snippet) it would be equal to DefaultDirName={pf}\{#MyAppName}\{#MyAppName}.
2nd from your Code snippet with Question MsgBox:
[Code]
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usUninstall then begin
if MsgBox('Do you want to delete all data files?', mbConfirmation,
MB_YESNO) = IDYES
then begin
DelTree(ExpandConstant('{app}'), False, True, True);
//first False makes that the main Directory will not be deleted by function
//but it will be by the end of Uninstallation
end;
end;
end;

Inno Setup: How to run a code procedure in Run section or before Run section?

I want to remove the old database before installing the new one, to update it for the user.
I have the following scenario:
In my Components section I have an option for the user:
[Components]
Name: "updateDatabase"; Description: "Update Database"; Types: custom; \
Flags: checkablealone disablenouninstallwarning
And I have in Code section, a procedure to execute, if the user selects this option, in the run section, before installing the new one.
[Code]
procedure RemoveOldDatabase();
begin
...
end;
[Run]
**--> Here I want to call RemoveOldDatabase if Components: updateDatabase is checked**
Filename: "database.exe"; StatusMsg: "Installing new database..."; Components: updateDatabase
The installation of the new database works fine. The problem is I want to remove the old one before installing the new one, calling the procedure RemoveOldDatabase.
Is it possible by only using Inno Setup?
Thanks.
One way, in my view really simple and still descriptive, is to execute your procedure as a BeforeInstall parameter function of your [Run] section entry. A BeforeInstall parameter function is executed once right before an entry is processed (and only if it's processed, which in your case is when the component is selected). You would write just this:
[Run]
Filename: "database.exe"; Components: UpdateDatabase; BeforeInstall: RemoveOldDatabase
[Code]
procedure RemoveOldDatabase;
begin
{ ... }
end;

Inno setup search for existing file

How can I search for an existing exe file and then use that directory for my installer ?
If the exe file is not found I would like the user to browse for the path. In case the exe file is installed somewhere else.
Senario 1 (most common cases):
Default dir is c:\test\My program
This should be shown as the path on the "Select Destination Location" page
When the user press Next, there should be a check. To make sure that the default dir exist (c:\test\My program)
If it exist, the user should just continue to the Ready to Install page.
Senario 2 (very seldom cases):
Default dir is c:\test\My program
This should be shown as the path on the "Select Destination Location" page
When the user press Next, there should be a check. To make sure that the default dir exist (c:\test\My program)
If it does not exist, the user should be prompt for the path to "My program". The user should afterwards continue to the Ready to Install page.
I then just trust that the user selects the correct path
How can I do this in InnoSetup ?
I do a similar thing with my installer already. The first thing I do is need to read the registry value from the program, and if that registry value is absent then I select that program's default directory. For example:
DefaultDirName={reg:HKLM\Software\Activision\Battlezone II,STInstallDir|reg:HKLM\Software\Activision\Battlezone II,Install121Dir|{pf32}\Battlezone II}
Now, the user runs the installer, and it has to check if the program is in the right folder. It does so by checking that the program's executable file already exists. I use this piece of code to do so.
{ Below code warns end user if he tries to install into a folder that does not contain bzone.exe. Useful if user tries to install into addon or any non-BZ2 folder. }
function NextButtonClick(CurPageID: Integer): Boolean;
begin
Log('NextButtonClick(' + IntToStr(CurPageID) + ') called');
case CurPageID of
wpSelectDir:
if not FileExists(ExpandConstant('{app}\bzone.exe')) then begin
MsgBox('Setup has detected that that this is not the main program folder of a Battlezone II install, and the created shortcuts to launch {#MyAppName} will not work.' #13#13 'You should probably go back and browse for a valid Battlezone II folder (and not any subfolders like addon).', mbError, MB_OK);
end;
wpReady:
end;
Result := True;
end;
The above code simply checks that the target executable exists and warns the user if it does not, giving him the chance to go back and change directories but also to go ahead with the install anyways.
Also, as you appear to be installing a patch or addon to an existing program, I recommend you set
DirExistsWarning=no
AppendDefaultDirName=false
And optionally to prevent an unnecessary screen if you are not creating start menu entries
DisableProgramGroupPage=yes
I would make a file input page and let user choose the Picture.exe binary location manually, when it won't be found on expected location.
You can follow the commented version of this code:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
OutputDir=userdocs:Inno Setup Examples Output
[Files]
Source: "CurrentBinary.exe"; DestDir: "{app}"
Source: "PictureExtension.dll"; DestDir: "{code:GetDirPath}"
[Code]
var
FilePage: TInputFileWizardPage;
function GetDirPath(const Value: string): string;
begin
Result := '';
if FileExists(FilePage.Values[0]) then
Result := ExtractFilePath(FilePage.Values[0]);
end;
procedure InitializeWizard;
var
FilePath: string;
begin
FilePage := CreateInputFilePage(wpSelectDir, 'Select Picture.exe location',
'Where is Picture.exe installed ?', 'Select where Picture.exe is located, ' +
'then click Next.');
FilePage.Add('Location of Picture.exe:', 'Picture project executable|Picture.exe',
'.exe');
FilePage.Edits[0].ReadOnly := True;
FilePage.Edits[0].Color := clBtnFace;
FilePath := ExpandConstant('{pf}\Picture\Picture.exe');
if FileExists(FilePath) then
FilePage.Values[0] := FilePath;
end;

Resources