5/7/11

How to Uninstall VB Programs Programmatically

Under normal circumstances, the easiest way to uninstall programs is to go through the control panel "Add and Remove Programs" interface. However, it is also possible to uninstall programs directly from Visual Basic by using the the WMIC (Windows Management Instrumentation Command-line) application.
    • 1

      Open Visual Basic and create a new project by clicking "File" and "New Project."

    • 2

      Double-click the text box and button components in the "Toolbox" to add one of each to your program. The text box will hold the name of the program to uninstall, and the button will initiate the uninstall process.

    • 3

      Double-click the button to create a "Click" event and paste the following code:

      dim result = Shell("wmic product where name=""" & TextBox1.Text & """ call uninstall", AppWinStyle.MaximizedFocus, True)

      MessageBox.Show(result)

      This calls the wmic command to uninstall the product named in the textbox. It then shows the results to the user in a messagebox.

  • No comments: