kimosavi
Posts: 4
Joined: Mon May 22, 2006 11:06 pm

stop install if file exists

Hi all,

newbie and trying the version. I do now VB and I am trying to make the installation stop or rollback if a file exist in the target directory where you specify to install the software.

right now I am running a function in at Appseach inside installexecutesequence since I don't know where they are going to install the tool, I have to check AFTER they specified the target directory.

the function finds the file, but does not stop the installation. How can I fix it or if you can guide me to another way will be great! thanks!

here is the function

Set fs = CreateObject("Scripting.FileSystemObject")
if fs.fileexists(session.property("APPDIR") & "ICTool.MDB") then
MsgBox "The ICTool was already installed in another computer, please use the Install for Workstations to setup the tool in your computer. Aborting", vbCritical+vbOKOnly, "IC Tool Setup"
Session.DoAction("msiDoActionStatusFailure")
End if
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi,
I do now VB and I am trying to make the installation stop or rollback if a file exist in the target directory where you specify to install the software.
You don't need to use a custom action to condition the installation of a package. You can do this very easy in Advanced Installer by using a "File Search" plus a "Launch Condition". Here how to do this:

1. Switch to "Search" page and add "New File Search->Add Location". In the Name field specify the file name that you want to search for. You can learn more about how to schedule a file search in the online documentation, please follow this link:
http://www.advancedinstaller.com/user-guide/search.html
2. Switch to "Launch conditions" page and use the search result as a launch condition like this:
Condition: NOT RESULT_PROPERTY
Description: File already exist on this computer.

Regards,
Gigi
__________________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com
kimosavi
Posts: 4
Joined: Mon May 22, 2006 11:06 pm

Thanks!

The first time I tried it did not worked so well, but I put the property in the correct category and worked just fine!

thank you soo much!
kimosavi
Posts: 4
Joined: Mon May 22, 2006 11:06 pm

here is what I did.

1. created a new search RESULT_PROPERTY
filename: ictool.mdb
path: [APPDIR]
depth: 0

2. created a launch condition
NOT RESULT_PROPERTY
file exists

3. custom action
under InstallExecuteSequence
under AppSearch
new action : Property Set with Formatted
property name: RESULT_PROPERTY
formatted Text: [RESULT_PROPERTY]

4. custom action after 3 (to check the value of result)
MsgBox Session.Property("RESULT_PROPERTY")

Ok now the syntoms

1. with the file in the folder
let me go all the way to selecting the path, but after just a empty
msgbox (step 4) appears and the installation keeps on going.
2. without the file in the folder
same effect
3. with file in the root folder of the drive
stops at the begining of the installation

let me know what i am doing wrong.

basically what I am doing is this. the tool will be installed in a network drive, I want to prevent other users that might be able to install the tool from other computers in the network to overwrite the primary installation, I do this by checking if a file exists in the folder they want to install the application, if so I stop the installation.

Thanks!
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi,

At the search time the APPDIR property is not available because this property is resolved on "CostFinalize" standard action. In previous post I was sugesting conditioning the installation based on the result of a search (search performed in all directory structure from local computer by leaving the "Path" field empty).
3. custom action
under InstallExecuteSequence
under AppSearch
new action : Property Set with Formatted
property name: RESULT_PROPERTY
formatted Text: [RESULT_PROPERTY]
This type of custom action sets a property from a formatted text string, so in the way that you use this custom action has no effect.
I do this by checking if a file exists in the folder they want to install the application
From what you say I understand that there is no problem if the application is installed multiple times on the same network drive but in different locations. In this case the file search does not work. Here's how you can do this:

1. Schedule a "New Attached Custom Action" under the "InstallExecuteSequence->Begin".
2. Set as "Function Name" the function name in the script file ("Test").
3. Execution Properties: Synchronous execution, check return code
4. Execution Options: Immediate execution
5. Scheduling Options: Always Execute
6. Execution condition: Not Installed

I have modified your script in order to work:

Code: Select all

Function Test
Set fs = CreateObject("Scripting.FileSystemObject")
if fs.fileexists(session.property("APPDIR") & "ICTool.MDB") then
MsgBox "The ICTool was already installed in another computer, please use the Install for Workstations to setup the tool in your computer. Aborting", vbCritical+vbOKOnly, "IC Tool Setup"
Test = 3
End if
End Function
If the file is found the function returns 3 to indicate that the installation must be aborted.

Regards,
Gigi
_________________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com
kimosavi
Posts: 4
Joined: Mon May 22, 2006 11:06 pm

It worked great!

Thanks a million!
splay
Posts: 58
Joined: Tue May 15, 2007 6:09 pm

Hi,

I am doing the same thing and here is my function from my vbs file

Function test


'test = true 'Setting it to true straight away

On Error GoTo 0


Set objConnection = CreateObject("ADODB.Connection")


On Error resume next




objConnection.Open "Provider=SQLOLEDB.1;Data Source=" & Session.Property("SERVER_PROP") & "; Initial Catalog=" &

Session.Property("DATABASE_PROP") & ";user id = '" & Session.Property("USERNAME_PROP") & "';password='" &

Session.Property("PASSWORD_PROP") & "'"


If Err.Number = -2147217843 Then
test = false
MsgBox "The USER details you supplied are incorrect"


ElseIf Err.Number = -2147467259 Then
test = false
MsgBox "Cannot connect to database, please check Server and Database name"


End If


On Error GoTo 0


End Function



I set the Published event on the Next Button on the dialogue that I want this to vbs to run and set the condition to test = true have also tried just true on its own.

I get my alert saying the db connection has a problem but the installer just progresses on to the next screen.

Any help?

Thanks
Tony
[/img]
ciprian
Posts: 259
Joined: Thu Jul 14, 2005 12:56 pm
Location: Craiova, Romania
Contact: Website

Hi,

In order for the installation to be aborted the function must return 3 instead of false.

So in the script replace test=false with test=3.

Regards,
Ciprian
Ciprian Burca
Advanced Installer Team
http://www.advancedinstaller.com

Return to “Common Problems”