Wednesday, April 11, 2012

How to uninstall windows application using ANT

Let's now pretend we'd like to uninstall standard windows application. Manually you would be doing the following:
1. Go to Uninstall programs
2. Locate the application you'd like to uninstall and then pass through set of dialogs.

But we'd still like to do it automatically. So to do that we need to know the application name we're going to get rid of. This name should be identical to one registered in the system.
Obviously ANT only reproduces the actions the human can do so if we uninstall the application via cmd we would use wmic tool. Make sure you have one (I'm sure you do) but just call it for the first time to let it register in the system.

So the line will look like this wmic product where name="Your Application Name" call uninstall


Lets use execute command to reproduce this line. Finally the script will look like this:


<project name="uninstall-application" default="default">
 
    <target name="default">
        <exec executable="wmic">
         <arg value="product"/>
         <arg value="where"/>
         <arg value="name=&quot;${application.to.uninstall}&quot;"/>
         <arg value="call"/>
         <arg value="uninstall"/>
        </exec>
    </target>
  
</project>

Just propagate application.to.install property to your script and enjoy. That is all. Not the rocket science.

No comments:

Post a Comment