Jump to content

Batch file install and uninstall in one


ZileXa

Recommended Posts

Hi,

For a little project, I want to do something I know is possible but forgot how to. I have done this a few years ago.

The idea: create a .cmd to install something e.g. copy files around and add uninstall info.

Now create a second .cmd to uninstall e.g remove files and uninstall info.

Now that we have install.cmd and uninstall.cmd, the idea is to combine both in installer.cmd,

Installer.cmd consists of two parts:

: INSTALL

COPY ....

GOTO EOF

: UNINSTALL

DEL ...

GOTO EOF

EXIT

Now it should be possible to run the batch file like this:

installer.cmd INSTALL --> this would call the INSTALL part and skip the Uninstall part.

installer.cmd UNINSTALL --> this would call the UNINSTALL part and skip the Install part.

Unfortunately, I am missing something because this is not working... but the idea is possible. Help appreciated!

Link to comment
Share on other sites


Here is an example based on your sample which may help.

@ECHO OFF
ECHO=%~1 | FINDSTR/BI [//-][UI] >NUL || (
ECHO=To use this file you must use an appropriate switch & ECHO=
ECHO= -u ^| -U ^| /u ^| /U Unistallation Routine & ECHO=
ECHO= -i ^| -I ^| /i ^| /I Istallation Routine & ECHO=
PAUSE & GOTO :EOF)
SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
SET "_P=%~1"
IF /I %_P:~1,1% EQU U GOTO UNI
REM Installation tasks go below here
::Example
ECHO=COPY ....
GOTO :EOF
:UNI
REM Uninstall tasks go below here
::Example
ECHO=DEL ...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...