Link to home
Start Free TrialLog in
Avatar of wei_shou
wei_shouFlag for Netherlands

asked on

How to create an uninstall function using VS2005?

I'm using Visual Studio 2005 to create a setup project for my application (written with C#). That part went fine. However I have problem to build the uninstall function. I'd like to create an uninstall icon on the programs menu, so users could easily uninstall my application on  their local.

I only know that I can use command "msiexec /u <program name>.msi" to do the uninstallation. But that would require to deploy the big MSI file onto user's local. That's a pain.

Would you please let me know whether there's any "grace" way to build the uninstall function?
ASKER CERTIFIED SOLUTION
Avatar of Thejaka
Thejaka
Flag of Sri Lanka image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wei_shou

ASKER

Thanks for your quick response! But how to make the shortcut runs this command line?

After selected "User's Programs Menu" in VS2005 setup project, and right click to pick up item "Create New Shortcut", I'm stuck on the "Select Item in Project" windows, which forces me to relate the shortcut with an existing file. Please advise.
Method 1:

1) Create the shortcut on your local system
2) Put it in the project folder of your application
3) In Solution Explorer, right click on the project and click Refresh
4) On the Project menu, click Show All Files
5) In Solution Explorer, right-click the shortcut file and then click Include In Project
6) In Solution Explorer, right-click the shortcut file, and then click Properties
7) Set the Build Action property to Content
8) In the File System Editor, select the folder into which the shortcut should go
9) Add "Project Output" -> "Content Files"
9) Rebuild the setup and deployment project


For more info, see:

http://support.microsoft.com/kb/837220
Method 2:

1) Create a windows batch file such as Uninstall.bat
2) Include statement "msiexec /x {productcode}"
3) Include the batch file in the application project, as content
4) Create a shortcut to this in the Setup Project
5) Include in start menu group


Link:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=219564&SiteID=1
Thanks for your detailed explanation. Hopefully this would be my last question.

When I tried with method 2, a DOS window always appeared as the batch file is being triggered by the uninstallation process. My question is how to make it this DOS window invisible? (I don't quite understand how to "Include the batch file in the application project, as content").

I'd prefer a way to do the uninstallation without hard code {productcode} anywhere in the project. Is there an graceful solution for that with VS2005?

The {productcode} is an integral part (property) of the MSI package. The Installer system is designed to identify the product using this GUID. The uninstall information in the registry is recorded under this GUID (using the GUID as an ID/Key). It is a required property, and will be there even if you don't use it for your purpose. The only way to avoid using a productcode is to use an alternate Packaging/Installer system altogether, meaning you avoid using MSI.

By using {productcode} in your shortcut, you're actually using the same identifier as used when you uninstall your app from Add/Remove Programs in Control Panel. I guess this is as "Graceful" as it gets :)

When you use a batch file, there is no way to hide the window. You can start it up minimized, by modifying the shortcut properties, but that's about it.

Instead of using a batch file, you can write your own exe to do the same as it does. This way, you can write it to run without a window.

To add a file to the project as content, simply drag and drop the file into where you want it to go in Solution Explorer. Then open the property page for the file and set the Build Action property to Content (If it isn't already that).
This means the file will be included in  the project output, but won't be compiled or built. Build Action for a batch file is content by default, so I guess you won't even have to worry about that.
Thanks for your time and help!