Results 1 to 8 of 8

Thread: [RESOLVED] batch file to uninstall and install program

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Resolved [RESOLVED] batch file to uninstall and install program

    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,

    Code:
    @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
    steve

  2. #2
    Hyperactive Member Quiver318's Avatar
    Join Date
    Sep 2007
    Posts
    260

    Re: batch file to uninstall and install program

    Batch files are pretty limited as installers and I would recommend using something like the Inno Setup 5 installer (which is free) or the AutoIT scripting language (which is free), but with being said; you just try to run the uninstaller which is typically found with in the installation directory or under the Window installer directory (if it is an MSI isntaller). If it runs, it is was intalled. If not, it was not. Either way, you just keep going with your script after you try running the uninstaller.

    You could also use the IF EXIST command to see if any main components already exist, but this would only work if the user installed to the default directory.

    Good Luck!

  3. #3
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: batch file to uninstall and install program

    I'm just giving some advices, i haven't tested nothing of this

    Code:
    IF EXISTS filepath
    This batch command can check if a file exists

    You can write to some file.BAT some data that your installer is doing

    If it creates a directory you write to taht file
    rd directory_name

    if it makes/copies a file you add a command
    del file_name

    etc..

    When that file is called it will execute those commands and probably unistall your program

    Edit:
    Command
    @echo del C:\test.txt >> Anotherfile.Bat
    will open Anotherfile.Bat for append and add a "del C:\test.txt" to it.
    Last edited by Dungeon Keeper; Jul 5th, 2009 at 09:06 AM.
    No, that wont do!

  4. #4
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: batch file to uninstall and install program

    Quote Originally Posted by Quiver318 View Post
    You could also use the IF EXIST command to see if any main components already exist, but this would only work if the user installed to the default directory.
    Application can be installed anywhere on disk, but a uninstall file can be somewhere else at a known position.

    For example \uninstall\MyApp_uninstall.bat

    Quote Originally Posted by Quiver318 View Post
    Batch files are pretty limited as installers
    No, that wont do!

  5. #5
    New Member
    Join Date
    Jul 2009
    Posts
    13

    Re: batch file to uninstall and install program

    for my bat installers, i packed install files into 7-zip(makes it alot smaller) and used a bat installer with zipp.exe, works pretty good, i will have to look closer on it for detecting and uninstalling

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: batch file to uninstall and install program

    Hello,

    I managed to solve my problem. I was very simple, I am surprised I didn't think of it before.

    However, as I am using MSI I just set the 'removepreviousversion' to true and changed the product code.

    This now removes the previous version so there is no need to change anything about my bat file.

    Thanks for all the advice,
    steve

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: batch file to uninstall and install program

    Hello,

    I managed to solve my problem. I was very simple, I am surprised I didn't think of it before.

    However, as I am using MSI I just set the 'removepreviousversion' to true and changed the product code.

    This now removes the previous version so there is no need to change anything about my bat file.

    Thanks for all the advice,
    steve

  8. #8
    New Member
    Join Date
    Aug 2010
    Posts
    1

    Re: [RESOLVED] batch file to uninstall and install program

    Hi !
    I am trying to do something similar. Where can i look for "removepreviousversion" in the MSI file ?
    I am using ORCA to edit the msi file.
    Thanks in advance!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width