tags:

views:

927

answers:

2

Hello,

I am using the following bat file to install my application on a user computer. However, the client want to be able uninstall the application if the application is installed, and then install the new version of the application.

However, I have 2 problems.

1) how can I detect if the application is installed or not?

2) If it is installed, how can I uninstall it?

The application is a C# 2005.

Many thanks for any advice,

@ECHO OFF
:: Copy the configuration file
copy config.xml "%AppData%\DataLinks.xml"

:: Search for the CONFIG file, if this doesn't exit then the user doesn't have the .Net framework 2.0
SET FileName=%windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG
IF EXIST %FileName% GOTO INSTALL_DIALER
ECHO.You currently do not have the Microsoft(c) .NET Framework 2.0 installed.
ECHO.This is required by the setup program for CAT Dialer
ECHO.
ECHO.The Microsoft(c) .NET Framework 2.0 will now be installed on you system.
ECHO.After completion setup will continue to install CAT Dialer on your system.
ECHO.
:: Install the .Net framework and then run setup to install the CAT Dialerr 
PAUSE
ECHO Installing... this could take serveral minutes...Please wait....
START /WAIT NetFx20SP2_x86.exe
:: If the user cancels the installation of the framework exit batch file
IF errorlevel 1 GOTO EOF
Start CATSoftphone.exe
ECHO ON
EXIT

:: .Net framework has been skipped contine to install the dialer.
:INSTALL_DIALER
ECHO *** Skiped Dotnet Framework 2.0.50727 ***
ECHO Installing... Please wait...
START CATSoftphone.exe
ECHO ON
EXIT

Edit ==============================

<job id="ReInstall">
<script language="VBScript">
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
oExec = WshShell.Run("msiexec /uninstall {2E92DD55-37E9-4D6C-B55B-DAFD9DF583E2}" , 1 , true )
If oExec = 0 OR oExec = 1605 Then
    oExec = WshShell.Run("InstallUninstallBat.msi")
End If
</script>
</job>
+2  A: 

You might be better off using the popular (free) NSIS installer platform, rather than using batch scripts. It's possible to do all the same things you're doing with it and building an uninstaller is much easier.

Matthew Iselin
+1  A: 

Here at my company the same request is corresponded with a VB script which is something like:

<job id="ReInstallblabla">
<script language="VBScript">
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
oExec = WshShell.Run("msiexec /uninstall {3D96B234-EB0C-4AC3-89EC-E5CAB9AEC432}" , 1 , true )
If oExec = 0 OR oExec = 1605 Then
    oExec = WshShell.Run("blabla_setup.msi")
End If
</script>
</job>

If you are able to create a deployment project for your application, it is going to have a ProductCode which you may pass as parameter to msiexec. Return value of 0 means uninstall is successfull, 1605 means no installation with the given ProductCode is found.

Hope it helps.

tafa
Hello, I tested your script file and added my own productCode and name of msi. However, when I run it just quickly flashes and doesn't do anything. Am I missing something. I have edited my code with my script. Thanks.
robUK
I am not sure and it probably is not the cause but would you make sure msiexec is rpesent in your system. Moreover you may check the return value ('oExec' in the example) with WshShell.Popup for example.
tafa