Jump to content

Recommended Posts

Posted

Hello everyone, 

I'm working on a WMIC uninstaller. A quite simple one with a button to display product names in a editable list (for copy/paste purposes) but the main problem is that in order to achieve this, in my corporation, normal users cannot uninstall softs.

What I found/adapt so far:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("wmic uninstaller", 300, 152, 337, 380)

$Label1 = GUICtrlCreateLabel("Computername", 0, 8, 75, 17)
$Input1 = GUICtrlCreateInput(@ComputerName, 0, 32, 125, 21)

$Label2 = GUICtrlCreateLabel("wmic command", 150, 8, 77, 17)
$Combo1 = GUICtrlCreateCombo("Model_Computer", 150, 32, 125, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))

GUICtrlSetData(-1, "Current_user|Installed_Apps|Serial_Number|Bios_Version")

$Button1 = GUICtrlCreateButton("List Apps", 150, 72, 91, 49)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         case $button1
            $wmi = GUICtrlRead($combo1)
            $pc = GUICtrlRead($input1)
            call($wmi,$pc)

    EndSwitch
 WEnd
 
 Func Model_Computer($pc)
RunWait(@ComSpec & ' /c ' & 'wmic /node:' & $pc &' product get name > %temp%\apps.txt' ,"", @SW_HIDE)
$file=(@TempDir & "/apps.txt")
$fileread= FileRead($file)
MsgBox(0, $pc , $fileread)
FileDelete(@TempDir & "/apps.txt")
EndFunc

Here's the textual version I gave to my techs:

Create cmd shortcut on Desktop, run it as a different user (using their own admin accounts).
Once opened, type wmic
Once wmic loaded, type product get name
Wait for the list of installed soft to display
Type product where name="Exact App name" call uninstall
Type "Y" to confirm
Wait for task execution
Don't care about exit code
App is uninstalled (verified by getting the list again)!

In fact, I'd like to automatize this process.

Any ideas over here? :)

Thanks ^^

~~~ Doom Shall Never Die, Only The Players ~~~

  • Moderators
Posted

This is what I use, you could easily wrap a GUI around it:

#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

 

"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!

Posted

Hell yeah! :) 

That's just awesome. No need to user admin credentials or so... Your core have done my script! Piece of cake now :) 

Thanks a lot for that :)

 

~~~ Doom Shall Never Die, Only The Players ~~~

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
×
×
  • Create New...