I want to have two batch files install.bat
and uninstall.bat
that are in the same folder as my command-line program program.exe
.
I want the install.bat
to add the current location of program.exe
to the System Path
environment variable.
Then I want the uninstall.bat
to remove any paths to program.exe
from the System Path
environment variable.
Any ideas on how to do this?
Perhaps This earlier solution would be of assistance.
A modified file to custom-fit your situation would be
Essentially, the two batches are the same - the only difference is that for the
INSTALL
version, the directory is added into the path.For this reason, I've simply desgned it so that
thisbatch
would install the file, andthisbatch /u
would uninstall it.Naturally, the calling of the routine to get a final OK to change the
path
is optional.I don't know which options you require for the setx, so the command is simply ECHOed. You'd need to remove the ECHO from the SETX line to activate the setting of the path variable.
Note also that SETX does not set the target variable in existing or the current CMD instances - only those created in the future.
It's also important to remember that using the
uninstall
feature in this routine would remove the directory from the path without regard to the requirements of any other software.