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 g
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]
.
a slight variation on the batch file approach. if you don't want to show a command window, use a wscript file. supply [ProductCode] as before in Arguments
<job>
<?job debug="true" error="true" ?>
<script language="JScript">
var arg = [];
for (var i=0; i<WSH.Arguments.length; i++) {
arg.push( WSH.Arguments.Item(i) );
}
if (arg.length>0) {
var productcode = arg[0];
var v = new ActiveXObject("Shell.Application");
v.ShellExecute("msiexec.exe", "/x "+productcode, "", "open", 10);
}
WSH.Quit(0);
</script>
</job>
I did a combination of the accepted answer and Locksmith's answer to not see any flashes of command prompt or the command prompt itself. One pro of doing it like this is that you DONT HAVE to create a shortcut and set the arguments for it in order for it to work.
My createUninstaller.js file:
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.js", ForWriting, true);
ts.WriteLine("var v = new ActiveXObject(\"Shell.Application\");");
ts.WriteLine("v.ShellExecute(\"msiexec.exe\", \"/x "+productCode+"\", \"\", \"open\",10);");
ts.Close();
This file is added as a custom action at the commit action 'directory'. In order to actually get to this custom actions: right click your setup project>view>custom actions>right click commit 'directory'>add custom action. After you have to search for the createUninstaller.js file you created and add it.
Now to make the createUninstaller.js read the variables targetDir and productCode you have to
Right click the createUninstaller.js file in the setup project custom action
'commit' directory and go to properties window.
In properties you will see the 'CustomActionData' property. In there you just copy paste [TARGETDIR]|[ProductCode]
And VOILA! It should now add the Uninstall.js file which will work as soon as you double click it.
For removing the application I would use the [ProductCode] as a parameter, calling the msiexec from within the application itself - for a detailed guide as to creating the uninstaller please check this blog: http://endofstream.com/creating-uninstaller-in-a-visual-studio-project/
every time when u generate setup then always change product code. create a uninstaller shortcut and there u will find command line argument passing technique to sort cut. there u will write always "/u product code" product code u need to write here always.
put this code in main method of program.cs file
[STAThread]
static void Main()
{
bool flag = true;
string[] arguements = Environment.GetCommandLineArgs();
foreach (string str in arguements)
{
if ((str.Split('='))[0].ToLower() == "/u")
{
if (MessageBox.Show("Do you want to uninstall job board", "Are you Sure?", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
flag = false;
RemoveRegSettings();
RemoveIniFile();
string guid = str.Split('=')[1];
string path = Environment.GetFolderPath(Environment.SpecialFolder.System);
ProcessStartInfo si = new ProcessStartInfo(path + @"\msiexec.exe", "/i" + guid);
Process.Start(si);
Application.Exit();
return;
}
}
}
//
//************************************************
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
I realize this question has already been answered, but what I did was create a batch file with the following content:
start msiexec.exe /x %1
Using "start" prevents the command prompt from staying open during the uninstallation process and the %1 is replaced by the first argument you pass to the batch file when executing it.
I added the batch file to the application folder and created a menu shortcut that points to the batch file. If you right click the shortcut and select Properties Window. In there, add the following text to the Arguments property:
[ProductCode]
After building and running the installer, you'll have a start menu shortcut that calls the batch file and passes the product code as it was when that version of the application was built. The user will then see a prompt asking if the product should be uninstalled.
The only downside of this solution is that if the user browses to the application folder and double clicks the batch file, the uninstaller will give an error that the install package does not exist.