Jump to content

Program Uninstaller Script?


Recommended Posts

Hi, I tried to make autoit script that will automatically remove all selected program without restart, but it doesnt list all installed programs. Is it possible to make script go through UninstallW.exe /a /l command output and list all program names instead of going through registry, and then later use UninstallW.exe to launch program uninstaller (one at a time), and also activate topmost window to send keys if there are 2 windows with same name and class (like in ax64 time machine uninstaller)? (sorry for bad english)

Program Uninstaller.7z

Link to comment
Share on other sites

Hi.

I doubt you're going to get many people downloading and running all sorts of executables and bat files uploaded by a person who signed up less than an hour ago. Including from this post https://www.autoitscript.com/forum/topic/174445-disc-burner-script/

I suggest you just post your code (on the forum in code tags) and try to explain the difficulties you are having.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Program Uninstaller.au3

; www.autoitscript.com/forum/topic/142042-add-checkboxs-in-a-gui-list/
; www.autoitscript.com/forum/topic/142722-generate-program-list/

#include <GuiListView.au3>

#NoTrayIcon
Opt("TrayAutoPause", 0)
Opt('GUIOnEventMode', 1)
Opt('GUICloseOnEsc' , 1)
FileDelete ("Uninstall.txt")

Global $i
Global $sSft
Global $sGui = GUICreate('Select Programs You want to Uninstall:', 471, 500, -1, -1)
Global $sLvw = GUICtrlCreateListView('Program Name', 2, 2, 467, 470, -1, $LVS_EX_CHECKBOXES)
Global $SelectAll = GUICtrlCreateListViewItem("Check All", $sLvw)
GUICtrlSetOnEvent($SelectAll, '_AllSelect')
_ComputerGetSoftware($sSft)

For $i = 1 To ubound($sSft) - 1
    GUICtrlCreateListViewItem($sSft[$i], $sLvw)
Next
GUICtrlSendMsg($sLvw, 0x101E, 0, 450)
Local $exp = GUICtrlCreateButton('  Uninstall  ', 0, 475)
GUICtrlSetOnEvent($exp, '_Uninstall')
GUISetOnEvent(-3, '_AllExit')
GUISetState(@SW_SHOW, $sGui)

While 1
    Sleep(1000)
WEnd

Func _ComputerGetSoftware(ByRef $aSoftwareInfo)
    Local Const $UnInstKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    Local $i = 1
    Dim $aSoftwareInfo[1]
      For $j = 1 To 500
        $AppKey = RegEnumKey($UnInstKey, $j)
        If @error <> 0 Then Exitloop
        If RegRead($UnInstKey & "\" & $AppKey, "DisplayName") = '' Then ContinueLoop
        ReDim $aSoftwareInfo[UBound($aSoftwareInfo) + 1]
        $aSoftwareInfo[$i] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "DisplayName"), 1)
        $i = $i + 1
    Next
    $aSoftwareInfo[0] = UBound($aSoftwareInfo, 1) - 1
    Return _ArraySort($aSoftwareInfo)
EndFunc

Func _AllExit()
    GUIDelete($sGui)
    FileDelete ("Uninstall.txt")
    Exit
EndFunc

Func _AllSelect()
   Local Const $iCount = _GUICtrlListView_GetItemCount($sLvw)
   If Not _GUICtrlListView_GetItemChecked($sLvw, $SelectAll) Then
   For $i = 0 To $iCount
        _GUICtrlListView_SetItemChecked($sLvw, $i, 2)
   Next
        GUICtrlSetData($SelectAll, "Uncheck All")
   Else
   For $i = 0 To $iCount
        _GUICtrlListView_SetItemChecked($sLvw, $i, 0)
   Next
        GUICtrlSetData($SelectAll, "Check All")
    EndIf
EndFunc

Func _Uninstall()
    Local Const $iCount = _GUICtrlListView_GetItemCount($sLvw)
    FileOpen("Uninstall.txt", 2)
    For $i = 1 To $iCount
        If _GUICtrlListView_GetItemChecked($sLvw, $i - 1) Then
        FileWrite("Uninstall.txt", _GUICtrlListView_GetItemText($sLvw, $i - 1) & @CRLF)
        EndIf
    Next
        FileClose ("Uninstall.txt")
        ShellExecute("Uninstall.bat")
        Exit
EndFunc

uninstall.bat

@echo off
rem www.installmate.com/support/uninstall.htm

echo Preparing Uninstallation Process...
start automate.exe
del /f /q /a "installed.txt" >nul 2>nul
del /f /q /a "remove.txt" >nul 2>nul
UninstallW.exe /l /f>Installed.txt

SetLocal EnableDelayedExpansion
set /a num=0
for /f "usebackq delims=" %%x in ("Installed.txt") do (
set name=%%x
set name=!name:~0,-1!
set beginning=!name:~0,1!
if not "!beginning!"==" " set /a num=num+1 && echo !name!>Program!num!.txt
)

set /a num=0

:list
(
set /p name=
)<Uninstall.txt

for /f "usebackq tokens=1,* delims==" %%i in ("Installed.txt") do if "%%i"=="   DisplayName" set /a num=num+1 && if "%name%"=="%%j" type "Program!num!.txt">>"remove.txt"
for /f "usebackq skip=1 delims=" %%z in ("Uninstall.txt") do echo %%z>>Uninstall.new
move /y "Uninstall.new" "Uninstall.txt" >nul 2>nul
set /a num=0

(
set /p name2=
)<Uninstall.txt
if "%name2%"=="%name%" goto continue
goto list

:continue
del /f /q /a "Program*.txt" >nul 2>nul
echo Uninstalling Selected Programs...
for /f "usebackq delims=" %%y in ("remove.txt") do UninstallW.exe /w "%%y"
del /f /q /a "*.txt" >nul 2>nul

automate.ahk

#NoEnv  ; 
#NoTrayIcon  ; 
SendMode Input  ; 
SetWorkingDir %A_ScriptDir%  ; 

SetWinDelay, 0 ;
SetTitleMatchMode, 3 ;

WinMinimizeAll ;
Loop ;
{
Sleep, 500 ;
IfWinNotActive, Windows Task Manager ahk_class #32770
IfWinNotActive, ahk_class ConsoleWindowClass 
IfWinNotActive, ahk_class Progman
IfWinNotActive, ahk_class CabinetWClass
IfWinNotActive, ahk_class Shell_TrayWnd
IfWinNotActive, ahk_class Button
IfWinNotActive, ahk_class ClassicShell.CMenuContainer
IfWinNotActive, ahk_class DV2ControlHost
IfWinNotActive, ahk_class AutoHotkeyGUI
IfWinNotActive, ahk_class Notepad
   {
    WinGetTitle, Title, A
    WinGetClass, Class, A
    WinActivate, %Title% ahk_class %Class%
    WinSet, AlwaysOnTop, On, %Title% ahk_class %Class%
    Send !l ;
    Send !y ;
    Send !n ;
    Send !u ;
    Send {SPACE} ;
          Loop ;
          {
    Sleep, 200 ;
    IfWinExist, %Title% ahk_class %Class%
    {
             WinActivate, %Title% ahk_class %Class%
             WinActivate, %Title% ahk_class #32770
    Send {DOWN} ;
    Send !n ;
    Send !l ;
             Send !u ;
    Send !c ;
    Send !f ;
    Send {SPACE} ;
    }
    Else
    {
    Break
    }
           }
   }
SetTimer, AutoKill, 10
}

AutoKill:
IfGreater, A_TimeIdle, 2000, Exit
return

Problems:

1) Multiple uninstallers start at same time, if possible to put all code to program uninstaller.au3 and start 1 uninstaller, wait for it to finish and then start another

2) use UninstallW.exe /a /l command output to list all program names instead of going through registry

3)  use UninstallW.exe from autoit script instead of bat file to launch program uninstaller

4) keys are not automatically send if there are 2 windows with same name and class (like in ax64 time machine uninstaller). in that case i need to activate topmost window to send keys 

Edited by kosamja
Link to comment
Share on other sites

Hi.

I doubt you're going to get many people downloading and running all sorts of executables and bat files uploaded by a person who signed up less than an hour ago. Including from this post https://www.autoitscript.com/forum/topic/174445-disc-burner-script/

I suggest you just post your code (on the forum in code tags) and try to explain the difficulties you are having.

I dont think I understand what do you mean by all sorts of executables and bat files...

Link to comment
Share on other sites

@kosamja I don't know about the problems you'd want removed, but I see one semantics error with your code. When you use FileOpen() then you shouldn't be using anything other than returned handle to do file operations. On top of that  FileClose ("Uninstall.txt") does nothing except contributing to global pollution, hurting our mother Earth. And dolphins.

To answer the question about who you are - I have no idea. Who? People around here speak good old American. (JohnOne, yes I know, you speak that other language similar to it :P.)

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

 does nothing except contributing to global pollution, hurting our mother Earth. And dolphins.know, you speak that other language similar to it :P.)

lol :)

Link to comment
Share on other sites

To answer the question about who you are - I have no idea. Who? People around here speak good old American. (JohnOne, yes I know, you speak that other language similar to it :P.)

Do that means no help for new members not from america?

Link to comment
Share on other sites

  • Moderators

I would suggest going with 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

Only crapware, that doesn't properly register itself with the system, does not show up. If that is what you're after, you have other issues.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...