Saturday, February 11, 2012

Creating Installer and uninstaller in Visual Studio 2008/2010.


Creating Installer In Visual Studio 2008/2010
Hi Friends, it's very common requirements some time to create installer and uninstaller in .net windows application. I have give some ideas how to perform both of these operation in a single application.
Setp:-1. Right click on Solution - =>Add => New Proejct
setp-2 Select Other Project Types. Select SetupProject from VS Installed Templetes.
Setp-3 Give Proper name for Setup.
Setp-4 Filse System (Setup Window Opens)
setp-5 Select Application Folder in left panel and right click on right panel.
setp-6 Add-> Project Output-> Primary Output, click on Ok button
setp-7 Select user's Desktop in left panel and right click on right panel.
setp-8 Select Create Shortcut-Application Folder -> Primary output.
setp-9 Rename current desktop shortcut.Change Icon from Property.
setp-10 Do same things for user's Programs Menu.
setp-11 Finaly rebuild you setup project.
setp-12 Find you setup in relese folder of setup project.


Creating UnInstaller: ( In Visual Studio 2008/2010)

To create UnInsteller we need to do following Things:
Setp-1: First Create Insteller
setp-2. In the Setup Project –> File System windows –> Right Click “File System on Target machine” –> add a Special Folder, select System Folder;
Setp-3: 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.
Setp-4: ) Create a new shortcut under the ‘Users Program Menu’, Set Target to the System Folder which you created in the Step-3
and point it’s at the msiexec.exe. Rename the shortcut to ‘Uninstall Your Application’. Set the Arguments property to /x{space}[ProductCode].
       Note: To get Product code: select you setup Project and check in Property will display Product code, copy it including {} and palce it after /X <Space> <Product code>
Step-5: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.

That's it.. Good luck..







12 comments:

  1. Hi Gireesh, thanks for the tutorial. I get to the point of creating the Uninstaller, however I got stuck because I could not find the Product Code inside the setup project properties page. I've been clicking on just about everything on the IDE and still cant find that string of number resembling the product code described above. Any advice?
    I'm using VS2008 by the way.

    ReplyDelete
  2. Hi Henry:
    Product Code is not found in any item of Solution. Product code is associted with the Setup Solution
    To find Product code select you SetupSolution and click on the Property window of you solution
    You will find it. Other wise select you Setup Project and press F4. you will find property window.
    If you have any concern futher feel free to post here.

    ReplyDelete
  3. Hi Gireesh.. Thanks for help.
    My application was successfully uninstalled.

    Can you please suggest me how to uninstall the application when user try to install application which is already installed?
    I have changed setup project's version and set RemovePreviousVersion=true but after installation when I checked version in control panel it is showing latest but it is not binding new exe to i. It is running old application itself.
    Can you tell me why so?


    ReplyDelete
  4. Hi Ashwini,
    If you put RemovePreviousVersion=true and dont change ur application name or any other parameter then when u try to install same application it removes the previous version and install new one. I think you have changed setup projects version so that it's not removing the previous version.
    I will check it out by creating the setup and let u know soon.

    ReplyDelete
  5. I am unable to get Product Code.

    ReplyDelete
  6. Hi PKP, To get product key select your setup project, press F4, It will display a property window. Here you will find the Product key. (As you get controls property on widows form same way setup projects has it's property which contains product key)

    ReplyDelete
  7. Hi Gireesh Painuly, I get product key in Setup project, i was copied and pasted in Arguments of Application folder.then i buil project.however, when i open program folder i only see file setup i dont see uninstalled????and im understand about step 4(Rename the shortcut to ‘Uninstall Your Application’. Set the Arguments property to /x{space}[ProductCode].
    Note: To get Product code: select you setup Project and check in Property will display Product code, copy it including {} and palce it after /X ).Can u tell me detail about it.If u have a video show about topic:Creating Installer and uninstaller in Visual Studio 2008/2010.Please give me!!!
    Thank u very much...
    I looking for u...

    ReplyDelete
  8. Thx, helped me creating a shortcut to the uninstaller

    ReplyDelete
  9. Thanks, it helped me.But there is one problem i am facing. My application uses some exe files and some txt files which are all placed inside the application folder. There is another folder named 'output' inside the main application folder, where the files created by the application are placed.When i uninstall the app, this folder alone is not getting deleted .is there some setting/option to see that it gets deleted?But if the application has not created any output files, then the 'output' folder is getting deleted. could you please give me a solution.

    ReplyDelete
    Replies
    1. Hi Vinay,
      Sorry for the late reply. If you add all your folders through the output folder of the installer then un-installer takes care about it. It deletes all the dependent folders while un-installing the solution. If you add any file or folder out of the installer scope it will be not deleted from the un-installer. Please verify your file location.

      Delete
  10. I have a small project with MS Access as back end database.When i try to uninstall the software it removes all the database which i don't want to uninstall because when i try to install the software second time the data which i entered previously should be present.
    How can i solve this ? please help me.

    ReplyDelete
  11. I have a small project with MS Access as back end database.When i try to uninstall the software it removes all the database which i don't want to uninstall because when i try to install the software second time the data which i entered previously should be present.
    How can i solve this ? please help me.

    ReplyDelete