Similar Content

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?

Hi all,
I have a bit of code that works on my old Win10 PC, that fails on my new Win10 PC, and I think the only significant difference is the version of Autoit - old PC has 3.3.12, new has 3.3.14.
I couldn't find anything mentioned in the change logs though, so perhaps I'm wrong.
Anyway, the code to replicate my issue is:
Test('username', 'DOMAIN')
; THIS ERRORS:
;Test('localun', 'DOMAIN')
; THIS ERRORS:
;Test(' ', ' ')
; THIS ERRORS:
;Test('', '')
; THIS ERRORS:
;Test('localun', '')
; THIS ERRORS:
;Test('', 'DOMAIN')
Func Test($un, $dom)
$compName = 'PCNAME'
$FullName = '.'
$Description = '.'
; get the WIM object
$objWMIService = ObjGet("winmgmts:\\" & $compName & "\root\cimv2")
; get default user full name and description
$objAccount = $objWMIService.Get("Win32_UserAccount.Name='" & $un & "',Domain='" & $dom & "'")
If IsObj($objAccount) Then
$FullName = $objAccount.FullName
$Description = $objAccount.Description
EndIf
ConsoleWrite($FullName & @CRLF)
ConsoleWrite($Description & @CRLF)
Return
EndFunc
On my old PC this code will output just . and . for each of those line currently commented out. Which is fine.
On my new PC any of those commented out lines of code cause an error, and the script won't even compile.
$objAccount = $objWMIService.Get("Win32_UserAccount.Name='" & $un & "',Domain='" & $dom & "'")
$objAccount = $objWMIService^ ERROR
I'm very much a newb with the WMI stuff and objects, but it looks like the .Get property is failing when either $un or $dom aren't valid in v3.3.14, whereas in 3.3.12 the .Get would fail to return an object, which is then caught by the If statement.
Am I on track with this? Is there some new/better way to code the example so that 3.3.14 will compile it?