Jump to content
Sign in to follow this  
RonMaurice

Uninstall THEN Install Script

Recommended Posts

RonMaurice

I am attempting to write a script that checks to see if a program is currently installed on a users system, if so it is to run an uninstall of that program, then run an installation of a different program that is stored on the network. This is how the script looks as of right now...

 

Run("C:\Windows\System32\control.exe appwiz.cpl")
WinWait("Programs and Features")
WinActivate("Programs and Features")
Send("Symantec Endpoint Protection")
 
If Send("Symantec Endpoint Protection")=False Then
Run("chdistInstallsSymantecEndpointProtection")
Send("Setup")
Send("{Enter}")
 
elseif Send("Symantec Endpoint Protectection")=True Then
 
Send("{Enter}")
WinWaitActive("Programs and Features")
Send("{y}")
WinWaitActive("Please enter the uninstall password")
Send("###########")
Send("{Enter}")
Run("chdistInstallsSymantecEndpointProtection")
Send("Setup")
Send("{Enter}")
 
EndIf

 

When I run the script, if the Symantec app is not installed it just grabs the next program it decides it wants to, which always seems to be ScITE and uninstalls that program. Even still it never initiates the install of the new Symantec program. I feel like I am messing up at "If Send("Symantec Endpoint Protection")=False Then", as a matter of fact I'm about 99% sure that is where the issue lies but I cannot figure out how to word the script so that it checks to see if exact text exist, and if not to run a different set of instructions.

Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
computergroove

Run("C:\Windows\System32\control.exe appwiz.cpl")
WinWait("Programs and Features")
WinActivate("Programs and Features")
Send("Symantec Endpoint Protection") <---------------------- I think this is your problem--------------------------
 
If Send("Symantec Endpoint Protection")=False Then
Run("\\chdist\Installs\SymantecEndpointProtection")
Send("Setup")
Send("{Enter}")
 
elseif Send("Symantec Endpoint Protectection")=True Then
 
Send("{Enter}")
WinWaitActive("Programs and Features")
Send("{y}")
WinWaitActive("Please enter the uninstall password")
Send("###########")
Send("{Enter}")
Run("\\chdist\Installs\SymantecEndpointProtection\")
Send("Setup")
Send("{Enter}")
 
EndIf

When you send "symantec endpoint protection" then the app finds the closest thing to symantec in an alphabetical fashion. I would either search for the registry key of the program you are looking for and uninstall it via the uninstall.exe from the install directory or read all the programs installed into an array and compare the names to what you want to install and if it exists then send symantec end point protection. You also dont need to send the entire thread of characters, only the first 10 characters and it should work if you feel the need to do it this way.


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites
JLogan3o13

Why don't you get the installed applications from the registry instead? Much easier. Look at RegEnumKey example in the help file.

I would:

  • Enum through your keys looking for the software
  • Once found, read that software's uninstall string into a variable and then execute it.

 

You can also pull installed products through WMI:

#include <MsgBoxConstants.au3>

$sName = InputBox("Uninstall Wizard", "Please type the first few letters of the application name to search")
$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2")
$aProducts = $oWMI.ExecQuery("Select * from Win32_Product Where Name LIKE '%" & $sName & "%'")

For $app in $aProducts
    $popup = MsgBox($MB_YESNOCANCEL, "Uninstall Wizard", "Would you like to uninstall " & $app.Name & "?")
        If $popup = $IDYES Then
            $app.Uninstall()
        ElseIf $popup = $IDCANCEL Then
            ExitLoop
        EndIf
Next
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
RonMaurice

 

Why don't you get the installed applications from the registry instead? Much easier. Look at RegEnumKey example in the help file.

I would:

  • Enum through your keys looking for the software
  • Once found, read that software's uninstall string into a variable and then execute it.

 

You can also pull installed products through WMI:

#include <MsgBoxConstants.au3>

$sName = InputBox("Uninstall Wizard", "Please type the first few letters of the application name to search")
$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2")
$aProducts = $oWMI.ExecQuery("Select * from Win32_Product Where Name LIKE '%" & $sName & "%'")

For $app in $aProducts
    $popup = MsgBox($MB_YESNOCANCEL, "Uninstall Wizard", "Would you like to uninstall " & $app.Name & "?")
        If $popup = $IDYES Then
            $app.Uninstall()
        ElseIf $popup = $IDCANCEL Then
            ExitLoop
        EndIf
Next

 

After 3 seconds of looking at that my eyes started bleeding and seconds later my brain imploded!

I can understand what is going on in what you wrote at a basic level, but then got completely lost.

Are these things that I would be able to locate in the AutoIT help?

Share this post


Link to post
Share on other sites
JLogan3o13

You can search the forum for AutoIt ScriptoMatic, which will help you. But how's this (with comments):

#include <MsgBoxConstants.au3>

$sName = InputBox("Uninstall Wizard", "Please type the first few letters of the application name to search") ;Prompt user for the application to search on
$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2") ;Connect to the appropriate WMI hive
$aProducts = $oWMI.ExecQuery("Select * from Win32_Product Where Name LIKE '%" & $sName & "%'") ;Query for all installed products where the name is similar to that entered above

For $app in $aProducts ;For all installed products that are returned...
    $popup = MsgBox($MB_YESNOCANCEL, "Uninstall Wizard", "Would you like to uninstall " & $app.Name & "?") ;Ask User if they would like to uninstall
        If $popup = $IDYES Then ;If they click yes...
            $app.Uninstall() ;Uninstall
        ElseIf $popup = $IDCANCEL Then ;If user clicks Cancel
            ExitLoop ;Exit the Loop (don't show anymore options)
        EndIf
Next

For your use, you could take out the Inputbox line, and do something like this...

#include <MsgBoxConstants.au3>

$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2") ;Connect to the appropriate WMI hive
$aProducts = $oWMI.ExecQuery("Select * from Win32_Product Where Name LIKE '%Symantec%'") ;Query for all installed products where the name is similar to Symantec

For $app in $aProducts ;For all installed products that are returned...
    $popup = MsgBox($MB_YESNOCANCEL, "Uninstall Wizard", "Would you like to uninstall " & $app.Name & "?") ;Ask User if they would like to uninstall
        If $popup = $IDYES Then ;If they click yes...
            $app.Uninstall() ;Uninstall
        ElseIf $popup = $IDCANCEL Then ;If user clicks Cancel
            ExitLoop ;Exit the Loop (don't show anymore options)
        EndIf
Next

I would only keep the MsgBox if you have other Symantec products installed, to ensure you don't uninstall the wrong one. Otherwise, just change your For loop to something like this:

For $app in $aProducts ;For all installed products that are returned...
            $app.Uninstall() ;Uninstall
Next
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×