When we install any application, registry of system keeps the unisntall command in the
Property : UninstallString
So we will get the this cammnad from registry and save in the batch file and execute the
batch file.
Vb.net code for this as follow:
Imports Microsoft.Win32 Imports System.IO Module Module1Dim MyAppStr As String = "MySetup" Dim RegistryPath As String Dim RegistryKeyObj As RegistryKeyDim CurrentRegKeyObj As RegistryKeyDim IsMyAppBool As Boolean = False RegistryPath = Dim ProcessInfoObj As ProcessStartInfoDim UnInstallCmdStr As String = String.EmptyDim ProcessObj As New ProcessDim TempBachFile As StreamWriterSub Main()"SOFTWARE\MICROSOFT\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products" RegistryKeyObj = Registry.LocalMachine.OpenSubKey(RegistryPath) Try CurrentRegKeyObj = RegistryKeyObj.OpenSubKey(ApplicationObj).OpenSubKey( For Each ApplicationObj As String In RegistryKeyObj.GetSubKeyNames"InstallProperties")If Not CurrentRegKeyObj Is Nothing Then If String.Compare(CurrentRegKeyObj.GetValue("DisplayName").ToString, MyAppStr) = 0 Then UnInstallCmdStr = CurrentRegKeyObj.GetValue( TempBachFile = TempBachFile.WriteLine(UnInstallCmdStr) TempBachFile.Close() ProcessInfoObj = ProcessInfoObj.RedirectStandardOutput = "UninstallString").ToStringNew StreamWriter("Uninstall.bat")New ProcessStartInfo("Uninstall.bat")True ProcessInfoObj.UseShellExecute = False ProcessInfoObj.CreateNoWindow = False ProcessObj.StartInfo = ProcessInfoObj ProcessObj.Start() ProcessObj.WaitForExit() IsMyAppBool = True Exit For End If End If Next If IsMyAppBool = False Then Console.WriteLine( "Application : " & MyAppStr & " had not installed in the system.")End If Console.WriteLine(ex.Message) Catch ex As ExceptionEnd Try Console.ReadKey() End End Sub Module