none
Need help in uninstalling application using VB scripting

    Question

  • Hi friends,

    I am not able to find what is wrong with the below script. please help me in finding out where i went wrong.

    IfIsArray(arraySoftwareNames) Then
            strComputer = getComputerName()
            Set myWinManObj = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
            Set softwareCollection = myWinManObj.ExecQuery("Select * from Win32_Product")
            MsgBox"query done"
            ForEach softwareIn softwareCollection
                ForEach elementIn arraySoftwareNames
                    If element = software.NameThen
                        MsgBox"(" & software.Name & ")" & vbNewLine & "(" & element & ")"
                        software.Uninstall()
                        ExitFor
                    EndIf
                Next
            Next
        Else

    basically i am getting the application names from the registry and storing it in an array and then passing it to this function with the argument arraySoftwareNames. but when i execute the script softwares are not getting uninstalled and no error is also thrown.

    • Moved by Bill_Stewart Monday, December 30, 2013 8:28 PM Question outside reasonable forum scope
    Wednesday, September 18, 2013 2:43 PM

All replies

  • #1 The code as posted does not make any sense because too much is missing.

    #2 Remove all "On Error Resume Next" statements and fix errors.


    ¯\_(ツ)_/¯

    Wednesday, September 18, 2013 3:28 PM
  • Function uninstallSoftware(ByVal arraySoftwareNames)

        Dim strComputer, element, software
        Dim myWinManObj, softwareCollection, query
        
        IfIsArray(arraySoftwareNames) Then
            strComputer = getComputerName()
            Set myWinManObj = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
            Set softwareCollection = myWinManObj.ExecQuery("Select * from Win32_Product")
            ForEach softwareIn softwareCollection
                ForEach elementIn arraySoftwareNames
                    If element = software.NameThen
                        software.Uninstall()
                        ExitFor
                    EndIf
                Next
            Next
        Else
            uninstallSoftware = "A Valid array is not passed to this function"
        EndIf
        
    EndFunction

    This is the actual code. I am passing a array which contains the application name which i want to uninstall to this application. I am not using any on error resume next statements. And by the way i found out that turning off the UAC in windows 7 solves the problem. But i am getting an error in windows XP in "GetObject" method line.  Can you help me with this.

    I also want to know if there is any advantages or disadvantages in uninstalling using MSIEXEC.EXE\X over the above method.

    Wednesday, September 18, 2013 5:33 PM
  • One question at a time.

    Again you are not giving us any information.  You cannot say you are getting an error and keep the error a secret.

    What error.  Post the complete error message.


    ¯\_(ツ)_/¯

    Wednesday, September 18, 2013 7:01 PM
  • This is more direct and will avoid some errors:

    Set wmi= GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set col=wmi.ExecQuery("Select * from Win32_Product WHERE Name='" & software.name & "'")
    For Each item In Col
         item.Uninstall()
    Next
    


    ¯\_(ツ)_/¯

    Wednesday, September 18, 2013 7:05 PM