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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Create a shortcut using the form:

msiexec /x {productcode}

Substitute {productcode} with the actual product code GUID used for the setup.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wei_shouAuthor Commented:
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:
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

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

wei_shouAuthor Commented:
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.
wei_shouAuthor Commented:
Thanks for your time and help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.