Jump to content

How to use alternative to CType in Autoit?/Important Windows updates


Bester
 Share

Recommended Posts

Hello, 

i would like to ask for some help on how to write something like this in Autoit

If CType(update, WUApiLib.IUpdate3).BrowseOnly = True Then
    opt_updates = opt_updates + 1
 Else
    imp_updates = imp_updates + 1
 End If

I`m trying to find Important Windows updates only, but for some reason this code:

$ColNeeded = $objSearcher.Search("BrowseOnly=0 and IsInstalled=0 and IsHidden=0")

$update = $ColNeeded.Updates.Item($i - 1)

returns all update (important and optional) as important (even though BrowseOnly=0). I think i`m missing a reference to WUApi.DLL in my code but i couldn`t find anything else to help me :/

If someone could help me either by providing a Autoit alternative to 

CType(update, WUApiLib.IUpdate3).BrowseOnly = True

or another way to find only important Windows updates i would be very grateful.
Thank you

Link to comment
Share on other sites

If anybody else got this problem of "BrowsOnly=0" not working and would like to do find only important updates for Windows i came up with this solution.
Hope it`s going to help someone:

 

$obj_search = ObjCreate("Microsoft.Update.Searcher")
    $obj_search.ServerSelection = 2
    $obj_search.Online = True

    ;looking for updates
    $obj_result = $obj_search.Search("IsInstalled=0 and IsHidden=0") ;you can change this to something else (BrowsOnly=0 will not work)
    $obj_updates = $obj_result.Updates

    For $i = 0 To $obj_updates.Count - 1
        $obj_categories = $obj_updates.Item($i).Categories
        $s_Cat = ""
        $s_Cat = $obj_categories.Item(0).Name
        If $s_Cat <> "Updates" Or $s_Cat <> "Drivers" Or $s_Cat <> "Feature Packs" Then
            ;!!-- Important updates only --!!
            $array[0][0] += 1
            $array[$array[0][0]][0] = $obj_updates.Item($i).Title
            $array[$array[0][0]][1] = $s_Cat
            $array[$array[0][0]][2] = Round($obj_updates.Item($i).MaxDownloadSize / 1024)
            $array[$array[0][0]][3] = 1 ;to indicate important updates in array
        Else
            ;!!-- All Optional updates --!!
            $array[0][0] += 1
            $array[$array[0][0]][0] = $obj_updates.Item($i).Title
            $array[$array[0][0]][1] = $s_Cat
            $array[$array[0][0]][2] = Round($obj_updates.Item($i).MaxDownloadSize / 1024)
        EndIf

    Next
    ReDim $array[$array[0][0] + 1][5]

 

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

×
×
  • Create New...