pursuited112
Posts: 10
Joined: Mon Jul 20, 2009 7:46 am

[Solved]Search for a file, if exists, terminate installation

I am pretty sure that what I am trying to do is possible, however I cannot figure out how to do it. Now I have searched endlessly in the forum and cannot find my answer.

What I am trying to do is: Before the installation takes place, Advanced Installer searches for a file. If the file is found, terminate the installation and display a message stating something along the lines of: "Filename.exe has been found. Setup cannot continue until Filename.exe has been removed."

Could someone be kind enough and help direct me in going about this.

I thank you all in advance!
Last edited by pursuited112 on Tue Jul 21, 2009 12:06 pm, edited 1 time in total.
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Search for a file, if exists, terminate installation

Hi,

To do so you must use a search result from a New Search defined in the Search page. The result is represented by the name of the search.
The New Search will look for the file you are interested in and return the path if the file is found and an empty string otherwise.

The search result is a property which you will use in the Custom Launch Conditions tab from the Prerequisites page to establish if the MSI will run or not.
The condition set by you in the Expression field should look something like this:

Code: Select all

FILE_SEARCH
where FILE_SEARCH is the name of the search you've created.


Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
pursuited112
Posts: 10
Joined: Mon Jul 20, 2009 7:46 am

Re: Search for a file, if exists, terminate installation

Edit:
I noticed in the help that: "The installation will run only if the custom launch conditions are True. Otherwise, the launch condition description will be shown to the user."

So if I understand correctly, if anything I put in the Custom Launch page and it returns a true value, the setup will continue. Right?

If that is so, how do I make it so if it DOES find my search, dont install?

Edit 2:
I figured it out! I had to add a opperand.. Duh!
So I put NOT SEARCH and it terminated like I wanted too!


Now my new question is is there a way to show the user where the file was found so they can rid of the file and not have to search for it themselves?
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Search for a file, if exists, terminate installation

Hi,
I am assuming I have to do something like this SEARCH = TRUE then Terminate?
The search will not return TRUE or FALSE , it will return the path of the file it finds it or it will return an empty string otherwise.

Just set the condition in the Expression field as described above.
If the condition is not fulfilled the installation will stop all by its self, otherwise it will continue.
If that is so, how do I make it so if it DOES find my search, dont install?
If you want to stop the installation in case the search finds the file , just set the condition negated. Here is an example:

Code: Select all

 NOT  FILE_SEARCH 
Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
pursuited112
Posts: 10
Joined: Mon Jul 20, 2009 7:46 am

Re: Search for a file, if exists, terminate installation

Thank you kindly!

As I said in the post I figured it out.

Now what I am trying to figure out is (if its possible) to display a message of the location where the file resides so the user can delete the file.

So right now what it does:
If file is found, shows the message I have, terminate installation if file found.

What I want it to do is to also show a message telling the user where the file is so they can go to the directory and delete the file, thus saving the user time in finding the file.

If that is possible, how can I make it so it displays all instances of the file found along with all instances directories.
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Search for a file, if exists, terminate installation

Hi,
Now what I am trying to figure out is (if its possible) to display a message of the location where the file resides so the user can delete the file
To display the path of the file you can use the message box which announces the failure of the Custom Launch Condition. Follow these steps:

– select the Custom Launch Condition → Edit
– in the Edit Launch Condition dialog → Description field , being formated you can use properties to display a message, write this:

Code: Select all

 The file “filename” exist at this path: [FILE_SEARCH] . Please delete it in order to be able to install the program 
The “[FILE_SEARCH] ” represents the search result property.
If that is possible, how can I make it so it displays all instances of the file found along with all instances directories.
Advanced Installer doesn't supports this directly. To be able to make such a search you need to create a Custom Action using a script (VB or dll) that will search all the file's instances.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
pursuited112
Posts: 10
Joined: Mon Jul 20, 2009 7:46 am

Re: Search for a file, if exists, terminate installation

That is simply amazing! I cannot believe that this program can do all of these customized actions!

You have been a great help Bogdan.

I do have another question if you do not mind.

Is there a way to make the message that is displayed show a sentence on another line? Instead of it all being in a row?

Kinda like what Visual Basic can do with:

Code: Select all

"The first line text." & vbCrLf & " The second line text." 
or

Code: Select all

"The first line text." & vbNewLine & " The second line text."
Both will display like so:

Code: Select all

The first line text.
The second line text.
So with what I got right now (using my example) the installer will display my message like so:

Code: Select all

The first line text. The second line text.
Thank you for taking the time to help me out (among others)! Its greatly appreciated!

Also, is there a way to have it display a message through a script? Because if that is possible I know you can make a message box to display multiple lines then. So if possible, how would you execute a script through the formatted type text box? Would it be as simple as making a script and then doing [scriptname]?
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Search for a file, if exists, terminate installation

Hi,

Yes you can display a message through a script.

Follow these steps:

- go to the Custom Launch Condition you've created, reedit the the Description field by living in it just a simple notification message.
- now go to Custom Actions page
- right click on the InstallUISequence folder → Show Standard Actions → AppSearch
- right click on AppSearch → New Custom Action → Script Inline
- in the Script Text field you can put something like this:

Code: Select all

MsgBox "My search result : "+ Session.Property("FILE_SEARCH") & vbCrLf & " The second line text."
Session.Property("FILE_SEARCH") -> this line is used to access the properties of the installer.

- in the Execution Condition group of the custom action you've created you must set the Expression field to [FILE_SEARCH]. This way the script will run only if the file is found.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
pursuited112
Posts: 10
Joined: Mon Jul 20, 2009 7:46 am

Re: Search for a file, if exists, terminate installation

Thank you so much Bogdan! I am quite impressed with your knowledge of the program, you are a definite asset!

Everything you have explained has worked perfectly.

Seeing as much of what I am requesting is possible, I have more questions.

First:
Since I have my installer doing a search for a file, it can take some time. (Of course dependent on how many sub-directories I search)
Is it possible to have a progress bar show while its doing its search? If so, preferably have the progress bar be on the same dialog as the search.

Second:
The first dialog that shows is the searching of the file. As shown below:
Property: [SEARCHVALUE], Signature: FileSearchSign
Is there a way to customize that text to a more understandable text? So the user understands what the installer is doing and why its taking so long.

Make it say something like:
Searching for: Filename.exe
Please wait, as this can take a few seconds to a few minutes.
Third:
I am pretty sure this is not a built in feature in AI, but may be possible in a script.
Can you make the message box that shows up support colored text, bold, italics, and underline?

Fourth:
This is kinda going off what question three is about, but I thought I'd ask it in a separate question.
Can you make text in the message box a clickable link? Not neccessarily a URL link. More so a path location link.

Like this:

Its a message box that says something like this:
File: [MYFILE.EXE] was found at:
C:\USERS\MAIN\DESKTOP\MYFILE.EXE
Please remove the file to be able to continue installation.
That link was set to this thread, but in reality it would take you to the location of the file.

I am pretty sure that is all the questions I have... For now...
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Search for a file, if exists, terminate installation

Hi,
First:
Since I have my installer doing a search for a file, it can take some time. (Of course dependent on how many sub-directories I search)
Is it possible to have a progress bar show while its doing its search? If so, preferably have the progress bar be on the same dialog as the search.
A progress bar can't be displayed when running a search.

Second:
Is there a way to customize that text to a more understandable text? So the user understands what the installer is doing and why its taking so long.
This text appears on the PrepareDlg, from the Dialogs page. It is defined in Windows Installer so you can't change it. But you can delete the empty static text fields (those that have no text) and add one with the text you desire.

Third:
I am pretty sure this is not a built in feature in AI, but may be possible in a script.
Can you make the message box that shows up support colored text, bold, italics, and underline?

Fourth:
This is kinda going off what question three is about, but I thought I'd ask it in a separate question.
Can you make text in the message box a clickable link? Not neccessarily a URL link. More so a path location link.
These features are not supported by Windows Installer. You can try using Custom Actions.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
pursuited112
Posts: 10
Joined: Mon Jul 20, 2009 7:46 am

Re: Search for a file, if exists, terminate installation

This text appears on the PrepareDlg, from the Dialogs page. It is defined in Windows Installer so you can't change it. But you can delete the empty static text fields (those that have no text) and add one with the text you desire.
Well too bad I cannot edit what ActionText and ActionData say. I took your help you provided and just moved ActionText and ActionData down and added my own text in the middle. So it still explains to the user what is going on. So I am happy about that.

Final question and then this topic is 100% handled!

I want to be able to remove a file during installation. So I read this thread: How do I remove a file or folder during installation?

I already figured out "Find the path of a folder" using the help you provided in earlier posts.

That URL points to:
If you know the files which remain you can use File Removal Operations to remove all the files in the folder.
So I look into the URL that sentance provides, which take me: File Removal Operations

So In AI I goto: Project Definitions > Files and Folders

THIS IS WHERE I GET STUCK

I have figured out that if I add a file, I can goto "File Operations">"File Removal"

I am not sure what I would put in the component. Because what I read was: "The component which will trigger the file removal operation."

What I am trying to do is remove a file before or during setup. Preferably delete the file from the folder the [SEARCH]'s find.

So here is the scenario:
Setup Starts
Setup searches for File.exe
IF File.exe is found then:
-Message box displays: "File.exe has been found at: C:\Folder\Sub Folder\"
If File.exe is NOT found then: CONTINUE SETUP
----------what I want it to do----------
Message box: "Do you want setup to remove this file?" Choices: Yes or No
--Case | Yes:
---Message Box: "Setup has deleted File.exe from [Search]"
---CONTINUE SETUP
--Case | No:
---Message Box: "Setup has terminated. Please remove File.exe from [Search] and then run the setup"
---Terminate Setup
----------Working from here on out----------
Register Services, copy files, write registry, ect....

Now I am pretty positive that "what I want it to do" has to be done in a script. What I do not know how to do is setup AI to execute the script and where I would put it in AI.

My thought is writing a seperate application to find the files and delete the files.
Then goto Custom Actions>InstallUISequence>AppSearch>New Attached Custom Action or Add PreDefined Custom Action
Then under New Attached Custom Action or Add PreDefined Custom Action I select my Application I made with the condition of [SEARCH]

Right? Or am I over-thinking this?
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Search for a file, if exists, terminate installation

Hi,

Yes you do need a script (VB, Java, DLL) for that. Then you add it as a Attached Custom Action just after AppSearch, as you mentioned. Just set the Expression field of the custom action you've created to:

Code: Select all

SEARCH
so the action will run only if the search finds something.

The message boxes you want to display will be managed by the script. In the custom action that runs the you need to exit with an error code (3) to indicate that the custom action was failed if the file hasn't been deleted and in this case the installation will stop.

Here is a VBS custom action that stops the installation:

Code: Select all

Function TestFunction()
   TestFunction = 3
End Function 
Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
pursuited112
Posts: 10
Joined: Mon Jul 20, 2009 7:46 am

Re: Search for a file, if exists, terminate installation

Thank you Bogdan for all of your help.

I was able to achieve almost all of what I wanted, minus bold words in a message box. Which is a minor thing.

I also took the time to edit my first post to state: [Solved]

Thank you for the time you took in helping me out, it was greatly appreciated.

Kind Regards

Return to “Common Problems”