Jump to content
Sign in to follow this  
ahmet

WMIC uninstall

Recommended Posts

Hello,

I am trying to make a program that will uninstall some software, provided by some form of a list. I have this

; Generated by AutoIt Scriptomatic June 08, 2010
;#RequireAdmin
$sPartialName="java"
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

;$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
;$objWMIService=ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2")
$objWMIService=ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
   For $objItem In $colItems
       If StringInStr($objItem.Name,$sPartialName)=1 Then
           ConsoleWrite("Full name:" & $objItem.Name & @CRLF)

           RunAs("USERNAME",@ComputerName,"PASSWORD",0,@ComSpec & " /c" & ' wmic product where name="Java 9.0.4 (64-bit)" call uninstall /nointeractive',"C:\WINDOWS\system32\wbem",@SW_MAXIMIZE)
           ;Run('wmic product where name="Java 9.0.4 (64-bit)" call uninstall /nointeractive',"",@SW_MAXIMIZE)
           ExitLoop
       EndIf
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_Product" )
Endif

The script above fails uninstalling software despite providing username and password for admin account. If I run script with admin rights then the software gets uninstalled.

At the following link there is a script by JLogan3o13 but it does not either uninstall software, unless run as admin..

Is there some way to uninstall software using wim or wimc by providing user name and password?

 

Share this post


Link to post
Share on other sites

Just to clarify, you want to be able to run it and pass credentials rather than seeing the UAC prompt, is that correct? If that is the case, I would compile the uninstall script, and then from a second script run the compiled one with the RunAs (look in the help file) function - passing the username and password.


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

Share this post


Link to post
Share on other sites
1 hour ago, ahmet said:

Thank you for your help. Then I will most probably do it that way, if end user agrees. 

You can also use FileInstall to package the uninstall script with the script that runs it. (When Compiled)


My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Share this post


Link to post
Share on other sites

Hello,

you can run wmic with a partial Productname

wmic product where "name like '%java%'" list

for uninstall try this

RunAs("USERNAME", @ComputerName, "PASSWORD", 2,"wmic product where ""name like '%java 9%'"" call uninstall /nointeractive", @SystemDir & "\wbem", @SW_MAXIMIZE)

use logon_flag 2

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  

  • Similar Content

    • By KingOfNothing
      This is for mac address spoofing.
      Before a mod gives me the ban hammer for posting code such as this, id like to explain I recently had a necessity for it.
      A lot of places use mac addresses to identify devices/machines and control internet permissions.
      I myself love the xfinity wifi hotspots placed all around where I live as I can connect to them and save data usage instead of tethering my phone.
      BUT! They use a captive portal with a webpage interface in javascript and (not too much to my surprise), wifey says some of her crap wont open that page.
      I explained she can disable wifi on the device, use computer and spoof to the mac address of what she wants to use. Then sign into the portal as she would normally with computer.
      Once connected, shut the computer down and enable wifi for that device again. Once enabled shes got net access. edit: Wife looked at me like I was speaking latin.....lol
      ; ; ; Function: Set_Mac() ; ; Parameter(s): $s_Desired_Mac = Need I really explain? ; $s_Target_Net_Adapter = Network adapter name (one can use the adapter index as well but thats less "user friendly" ; $b_Toggle_Device = For my wife cuz it needs full automation for her to stop bothering me ; ; Author(s): KingOfNothing credz to google & autoitscript.com members ; ; ;===================================================================== Opt('MustDeclareVars', 0) ;cause its late in the morning and im just gonna trust this should still fly #include <WinApi.au3> $MacAddressRegKey = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007" ; ^^^ After making this I read online that this should be some "CurrentControlSet" ; key instead. However, I watched registry while changing things in adapter properties ; to see that key, which works fine on my 3 test machines.... ;easy example Set_Mac("Wireless Network Connection","",true) ;msgbox(0,"",Get_Mac()) Func Set_Mac($s_Targeted_Adapter, $s_Desired_Mac = "D20000000000", $b_Toggle_Device = true ) Local $sMac, $s_Tmp, $val, $sVar = "" $sMac = Get_Mac() while stringlen($s_Desired_Mac)< 12 and stringlen($s_Desired_Mac)> 0 ;this will append zeros if mac length is too short $s_Desired_Mac = $s_Desired_Mac & "0" wend if stringlen($s_Desired_Mac)> 12 then ;likewise if too many characters entered to function, then we should truincate some $s_Desired_Mac = StringLeft ($s_Desired_Mac,12) endif ;this creates a random mac address with very little actual thought behind it. ;Im sure theres some formal means to devising a valid mac address but this simple crap suits my needs atm.... if $s_Desired_Mac = "" then For $i = 1 To 10 $sVar= Chr(Random(48, 57, 1)) ;0-9 $s_Tmp = $s_Tmp & $sVar Next $s_Desired_Mac = "D2" & $s_Tmp $s_Desired_Mac = StringUpper($s_Desired_Mac) endif $val = RegWrite($MacAddressRegKey, "NetworkAddress", "REG_SZ", $s_Desired_Mac) if $val =0 then MsgBox(0,"Mac Address Changer ","Could not write to registry as needed to change your mac address!" & @CRLF & "Please restart this program with administrator rights!") Exit endif ;in order to benifit from changing the registry, one must disable/re-enable the adapter. ;This cmd line query to wmic prevents the need to do so in device manager manually if $b_Toggle_Device = true then ShellExecuteWait ("C:\Windows\System32\wbem\wmic.exe", "path win32_networkadapter where NetConnectionID=" & chr(34) & $s_Targeted_Adapter & chr(34) & " call disable" ,"",$SHEX_OPEN,@SW_HIDE) ShellExecuteWait ("C:\Windows\System32\wbem\wmic.exe","path win32_networkadapter where NetConnectionID=" & chr(34) & $s_Targeted_Adapter & chr(34) & " call enable" ,"",$SHEX_OPEN,@SW_HIDE) endif ;Would be smart to catch the return of the function there in some varible for error handling, but its too late for me to give a crap atm.... MsgBox(0,"Mac Address Changer", "Old Mac = " & $sMac & @crlf & "New Mac = " & $s_Desired_Mac) clipput($s_Desired_Mac) endfunc Func Get_Mac() Local $xRet $xRet= RegRead($MacAddressRegKey, "NetworkAddress") return $xRet EndFunc  
      Sorry bout the messy penmenship. Aint looked at the tidy thing yet....🧐
    • By jresine
      Hello, is it possible to know via a script or command, to have the percentage of disk usage of a process? thank you in advance.
      ps: see image

    • By Dwalfware
      HI
      Another head scratched
      Anyone solve how to get the IPV6 from WMI?
      I followed the usual SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID='" & GUICtrlRead($cboAdapters) & "'
      get the index 
      port it to 
      Local $query = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = " & _GetSelectedNIC(), "WQL", 0x30 )
      All i can see is IPv4 addresses
      My question is is there another place the IPv6 information is hiding? I configured my LAN with IPV6 and my wireless with IPv4 so I can see what shows.
      Thanks in Advance.
      PS. I did try google
       
    • By Dwalfware
      Hi Folks
      Can not get my head around this one.
      This function gets the DNS object s
      If you have two DNS entries fine. but if you have only one! Trouble
      $objItem.DNSServerSearchOrder[0] = Primary DNS
      $objItem.DNSServerSearchOrder[1] = Secondry DNS not always there. I need a way to return 0 if not there or the IP if its there.
      Or is there a way to tell how many objects there are in the "[?]"
      I'm terrible at WMI errors, thanks for help in advance.
      Func _GETcurrentNICinfo2() $oErrors = ObjEvent("AutoIt.Error", "Error_Handle") Local $DnsSecondry Local $objWMIService = ObjGet( "winmgmts:\\" & @ComputerName & "\root\CIMV2" ) Local $query = $objWMIService.ExecQuery("SELECT DNSServerSearchOrder FROM Win32_NetworkAdapterConfiguration WHERE Index = " & _GetSelectedNIC(), "WQL", 0x30 ) If @error Then Return 0 If NOT IsObj($query) Then Return 0 Else For $objItem In $query Return $objItem.DNSServerSearchOrder[1] next Endif EndFunc  
    • By nitron
      Hy All,
       
      again I got a question.
      I try to convert
      wmic PATH Win32_videocontroller GET adapterram
       
      i tried to to it like in this example but my knoledge is not good enough
         Local $oWMI = ObjGet("winmgmts:root\CIMV2")
         Local $oDisks = $oWMI.ExecQuery("select * from WIN32_DiskDrive")
       
      So i tired 
         Local $oWMI = ObjGet("winmgmts:root\CIMV2")
         Local $oGMRam= $oWMI.ExecQuery("Win32_videocontroller")
         $Memory=$oGMRam.adapterram
      but this does not work.
      I like to understand what i need to do?
       
×
×
  • Create New...