4

I was looking for an alternative for an uninstall in a setup project (while reading this) and tried the following, which sadly fails:

I made a Setup Project for a dummy application in C#. I added the output from its build and an Uninstall.bat file with this inside:

echo %1
msiexec /x %1

I then added a shortcut to that file with [Product Code] in the shortcut's Arguments field:

Shortcut

My rationale was that Uninstall.bat would be called with the product code (resolved) as an argument.

After setting that up, no dice, the argument isn't passed along to the installer from the shortcut. The output from the command window is:

ECHO is on.
msiexec /x

The %1 parameter doesn't seem present. Looking inside the LNK file in a binary editor, the product code appears to be present.

What's happening here?

Further attempts for various arguments and a simple echo:

  1. [Product Code] -> ignored
  2. {%hardcodedProductCode%} -> passed to batch as %1
  3. [Product Name] -> ignored
  4. Constant [Product Code] -> Constant only is passed to batch as %1
  5. [Product Name] Constant [Product Code] -> Constant only is passed to batch as %1, not %2
  6. [Product Name] Constant [Product Code] [UndeclaredVariable123] -> Constant only is passed to batch as %1
  7. $[Product Code] -> $ only is passed to batch as %1

The 5th example shows that variables are ignored somehow if the constant is bumped to position 1.

Community
  • 1
  • 1
MPelletier
  • 16,256
  • 15
  • 86
  • 137
  • To better know what is happening, ideas to try: (1) in the Arguments field, a constant parameter, a constant parameter and a variable, a variable other than [Product Code]. (2) Review the rest of the shortcut parameters, Target, etc. – PA. Mar 23 '11 at 07:44
  • Perhaps you have some missing quotes. Paths which contain spaces need to be enclosed by quotes. – Cosmin Mar 23 '11 at 11:18
  • @CosminPrivu There is no path in this. [Product Code] produces a string with no spaces. – MPelletier Mar 23 '11 at 11:31
  • @PA Ah! Interestingly if I hardcode the Product Code it will work. I wonder how the LNK file looks. That'll be for a little bit later today. – MPelletier Mar 23 '11 at 11:37

1 Answers1

3

First of all why you are adding $?

Parameters are defined in square brackets.

Set [ProductCode] or [PRODUCTCODE]

It should work, all vs arguments are one word, they do not have spaces an there is no $ sign.

Also have a look here, http://www.gogototo.com/how-to-add-a-uninstall-option-in-visual-studio-setup-project-without-writing-code.html

Akash Kava
  • 39,066
  • 20
  • 121
  • 167