I have a Visual Studio setup project. Upon installation, it creates an uninstall batch file in the application folder. IF the user wants to uninstall the product, he can go to "Add/Remove Programs", or he can just double-click the uninstall.cmd. The contents are:
%windir%\system32\msiexec /x {CC3EB7BF-DD82-48B9-8EC5-1B0B62B6D285}
The GUID there is the ProductCode from the Setup Project in Visual Studio.
But, in order for upgrades to work properly, I have to increment the Version number, every time I produce a new MSI. And, if I increment the Version number, then I also have to generate a new Guid for the ProductCode. Which means the static uninstall.cmd file needs to change.
How can I dynamically generate a batch file that contains the ProductCode for the, at build time?
You can run InstallCleanup.exe to remove all installed Visual Studio instances completely. If the answer is the right solution, please click "Accept Answer" and kindly upvote it.
From the Start menu in Windows, search for "installer", and then select Visual Studio Installer from the results. You might be prompted to update the Visual Studio Installer before continuing. If so, follow the prompts. In the Visual Studio Installer, look for the installation of Visual Studio that you want to repair.
I found this solution here
"Using Visual Studio 2005/2008, you don’t need to write any code to add a uninstall option for a Setup project (Yes I know some people can write code to do it)
1) In the Setup Project –> File System windows –> Right Click “File System on Target machine” –> add a Special Folder, select System Folder;
2) Into this system folder Add a file. Browse for msiexec.exe from local System32 folder and add it. Override default properties of this file as follows:
Condition:=Not Installed (make sure you put ‘Not Installed’ exactly like that, same case and everything), Permanent:=True, System:=True, Transitive:=True, Vital:=False.
3) Create a new shortcut under the ‘Users Program Menu’, Set Target to the System Folder which you created in the step 1. and point it’s at the msiexec.exe. Rename the shortcut to ‘Uninstall Your Application’. Set the Arguments property to /x{space}[ProductCode].
4) Build the project, ignore warning about the fact that msiexec should be excluded, DONT exclude it or the setup project wont build.
The ‘Not Installed’ condition and Permananet:=True ensure that the msiexec.exe is only placed into the system folder as part of the install IF it doesn’t aready exist, and it is not removed on an uninstall - therefore it;s pretty safe to ignore that warning and just go for it.
(Based on the description from SlapHead)"
I just made this work:
Add an uninstall.bat file to your project. The file contents is:
msiexec.exe /x %1
Make a shortcut to that batch file (say in User's Program Menu), specify in the shortcut's properties, next to Arguments: [ProductCode]
.
This is the script I wrote that creates an uninstall.cmd. It runs as a custom action during installation.
var fso, ts;
var ForWriting= 2;
fso = new ActiveXObject("Scripting.FileSystemObject");
var parameters = Session.Property("CustomActionData").split("|");
var targetDir = parameters[0];
var productCode = parameters[1];
ts = fso.OpenTextFile(targetDir + "uninstall.cmd", ForWriting, true);
ts.WriteLine("@echo off");
ts.WriteLine("goto START");
ts.WriteLine("=======================================================");
ts.WriteBlankLines(1);
ts.WriteLine(" Uninstall.cmd");
ts.WriteBlankLines(1);
ts.WriteLine("=======================================================");
ts.WriteBlankLines(1);
ts.WriteLine(":START");
ts.WriteLine("@REM The uuid is the 'ProductCode' in the Visual Studio setup project");
ts.WriteLine("%windir%\\system32\\msiexec /x " + productCode);
ts.WriteBlankLines(1);
ts.Close();
The result is a cmd file that always has the current ProductCode in it.
The downside of this is that ?the script that creates the uninstall.cmd remains in the installation directory. Not a huge problem but I don't like the rubbish in the install directory. I haven't yet tried to make the "createInstaller.js" self-deleting. That might work.
EDIT: yes, making the createInstaller.js self-deleting works fine.
I'm going to accept my own answer!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With