31290

WMIC uninstaller

3 posts in this topic

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 ~~~

Share this post


Link to post
Share on other sites



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

 

1 person likes this

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

Share this post


Link to post
Share on other sites

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 ~~~

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

  • Similar Content

    • luny
      By luny
      Hello all, this is what I got so far .. it opens and It won't put in words, I need to log in,,  oops didnt put in code. LOL
       
      #include <IE.au3>
      Local $oUser, $oPass, $oSubmit
      Local $sUser = "lit"
      Local $sPass = "abc"
      Local $url = "http://woodstock:9090/login.jsp?url=%2Findex.jsp"
       

      Local $oIE = _IECreate($url, 1)

      _IELoadWait($oIE)
      $oInputs = _IETagNameGetCollection($oIE, "input")
      for $oInput in $oInputs
          if $oInput.type = "text" And $oInput.name = "userid" And $oInput.size = "12" Then $oUser = $oInput
          if $oInput.type = "password" And $oInput.name = "password" And $oInput.size = "12" Then $oPass = $oInput
          if $oInput.type = "submit" And $oInput.value = "loginformtable" Then $oSubmit = $oInput
          if isObj($oUser) And isObj($oPass) And isObj($oSubmit) then exitloop
      Next
      $oUser.value = $sUser
      $oPass.value = $sPass
      _IEAction($oSubmit, "click")
      _IELoadWait($oIE)
       
       
      1  
       
       
    • WoodGrain
      By WoodGrain
      Hi guys,
      This is probably an obvious one, but I really don't use this command at all so am hoping you can spot my mistake.
      I'm running a powershell script on a schedule with the following script in a function, the function is being called in a loop, but the console process is not closing in the background and I end up with a bunch of console windows running in the background:
      Run(@comspec & ' /k PowerShell.exe -STA -NonInteractive -ExecutionPolicy ByPass -Command "& ''Z:\Powershell\365\GetNextDetails.ps1'' "', "", @SW_HIDE) Thanks!
    • FMS
      By FMS
      Hello,
      I've some troubles whit the run command.
      Below u see 2 command's , 1 is working and the other not. (the first isn't working)
      I think the problem is in te space between program and files.Also I've treid every thing i could think of or the helpfiles handed to me.
      (or maybe I din't find the correct answer:))
      I tried so mush that i don't know anymore if it's the space between program files or not.
      Could somebody point me in the right direction?
      Not working:
      Run(@ComSpec & " /c psexec -i \\127.0.0.1 -u username -p pass -h -d /accepteula C:\Program Files\some_prog\Shell.exe" ,"C:\tools", @SW_HIDE) Working :
      Run(@ComSpec & " /c psexec -i \\127.0.0.1 -u username -p pass /accepteula cmd" , "C:\tools" , @SW_HIDE)  
       
       
       
       
       
       
    • FMS
      By FMS
      hello,
      I'm trying to make a check if a process is running on a remote PC.
      This is what i got this far when I edit a found snippet on this forum.
       
      The function _CMDreturn returns the output of the command line command.
      In this output I want to scan if there is a line whit "process mspaint was not found".
      This I'm trying to do whit StringLeft.
      The problem is that I don't get any error's and also don't get a message if it doesn't exist.
      Could somebody say to me what I'm doing wrong here?
      Or iff there is a better way to do this?
      Thanks in advanced.
       
      #include <Constants.au3> $result= _CMDreturn('C:\Tools\Ps\pslist.exe mspaint') msgbox(0,"Version",$result) Func _CMDreturn($sCommand) $cmdreturn = "" $stream = Run(@ComSpec & " /c " & $sCommand, @SystemDir, @SW_HIDE, $STDOUT_CHILD + $STDIN_CHILD) While 1 $line = StdoutRead($stream) If @error Then ExitLoop If StringLeft($line, 32) = "process mspaint was not found on" Then msgbox(0,"not found",$line) EndIf $cmdreturn &= $line WEnd Return $cmdreturn EndFunc  
    • Eggsplorer
      By Eggsplorer
      Hi,
      I want to install chocolatey (https://chocolatey.org/) with AutoIt.
      I just need to send the following command to cmd:
      @powershell -NoProfile -ExecutionPolicy unrestricted -Command "(iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin This is what I tried:
      RunWait(@ComSpec & " /C " "@powershell -NoProfile -ExecutionPolicy unrestricted -Command "(iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin", ""); It didn't work propably because of the quotes.
      So I tried this:
      $code1 = "@powershell -NoProfile -ExecutionPolicy unrestricted -Command" $code2 = " (iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1" $code3 = " && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" RunWait(@ComSpec & " /C " & $code1 & $code2 & $code3, ""); Didn't work either.
      Any help?
      Thanks in advance =)