Sign in to follow this  
Followers 0
yucatan

Why this dont work?

8 posts in this topic

#include <date.au3>

$updateSession = ObjCreate("Microsoft.update.Session")

$updateSearcher = $updateSession.CreateupdateSearcher()

ConsoleWrite ("Searching for updates..." & @CRLF)

$searchResult = $updateSearcher.Search("IsInstalled=0 and Type='Software'")

ConsoleWrite ("List of applicable items on the machine:")

For $I = 0 To $searchResult.Updates.Count-1

$update = $searchResult.Updates.Item($I)

ConsoleWrite ($I + 1 & "> " & $update.Title & @CR)

Next

If $searchResult.Updates.Count = 0 Then

ConsoleWrite ("There are no applicable updates.")

Exit

EndIf

ConsoleWrite (@CRLF & "Creating collection of updates to download:")

$updatesToDownload = ObjCreate("Microsoft.update.UpdateColl")

For $I = 0 to $searchResult.Updates.Count-1

$update = $searchResult.Updates.Item($I)

ConsoleWrite ($I + 1 & "> adding: " & $update.Title & @CR)

$updatesToDownload.Add($update)

Next

ConsoleWrite (@CRLF & "Downloading updates...")

$downloader = $updateSession.CreateUpdateDownloader()

$downloader.Updates = $updatesToDownload

$downloader.Download()

ConsoleWrite ( @CRLF & "List of downloaded updates:")

For $I = 0 To $searchResult.Updates.Count-1

$update = $searchResult.Updates.Item($I)

If $update.IsDownloaded Then

ConsoleWrite ($I + 1 & "> " & $update.Title & @CR)

EndIf

Next

$updatesToInstall = ObjCreate("Microsoft.update.UpdateColl")

ConsoleWrite ( @CRLF & "Creating collection of downloaded updates to install:" )

For $I = 0 To $searchResult.Updates.Count-1

$update = $searchResult.Updates.Item($I)

If $update.IsDownloaded = 1 Then

ConsoleWrite ($I + 1 & "> adding: " & $update.Title & @CR)

$updatesToInstall.Add($update)

EndIf

Next

ConsoleWrite (@CRLF & "Installing updates...")

$installer = $updateSession.CreateUpdateInstaller()

$installer.Updates = $updatesToInstall

$installationResult = $installer.Install()

;Output results of install

ConsoleWrite ("Installation Result: " & $installationResult.ResultCode )

ConsoleWrite ("Listing of updates installed " & "and individual installation results:" )

For $I = 0 to $updatesToInstall.Count - 1

ConsoleWrite ($I + 1 & "> " & $updatesToInstall.Item($I).Title & ": " & $installationResult.GetUpdateResult($I).ResultCode & @CR)

Next

why this dont work ? i get a error.

Share this post


Link to post
Share on other sites



Looks like more people than me experienced some server lag just now :)


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Looks like more people than me experienced some server lag just now :)

I hope thats what that is.... man thats a lot of duplicate posts.

Share this post


Link to post
Share on other sites

huh..??

Share this post


Link to post
Share on other sites

huh..??

What don't you get? You posted the same topic 15 times. See page 2 in General Help & Support.

Share this post


Link to post
Share on other sites

Replace

If $update.IsDownloaded = 1 ThenoÝ÷ Ùh­«­¢+Ù%ÀÌØíÕÁѹ%ͽݹ±½ôQÉÕQ¡¸

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Works for me now:

#include <date.au3>

$updateSession = ObjCreate("Microsoft.update.Session")
$updateSearcher = $updateSession.CreateupdateSearcher()

ConsoleWrite("Searching for updates..." & @CRLF)

$searchResult = $updateSearcher.Search("IsInstalled=0 and Type='Software'")

ConsoleWrite("List of applicable items on the machine:")
For $I = 0 To $searchResult.Updates.Count - 1
    $update = $searchResult.Updates.Item($I)
    ConsoleWrite($I + 1 & "> " & $update.Title & @CR)
Next

If $searchResult.Updates.Count = 0 Then
    ConsoleWrite("There are no applicable updates.")
    Exit
EndIf

ConsoleWrite(@CRLF & "Creating collection of updates to download:")
$updatesToDownload = ObjCreate("Microsoft.update.UpdateColl")

For $I = 0 To $searchResult.Updates.Count - 1
    $update = $searchResult.Updates.Item($I)
    ConsoleWrite($I + 1 & "> adding: " & $update.Title & @CR)
    $updatesToDownload.Add($update)
Next

ConsoleWrite(@CRLF & "Downloading updates...")
$downloader = $updateSession.CreateUpdateDownloader()
$downloader.Updates = $updatesToDownload
$downloader.Download()

ConsoleWrite(@CRLF & "List of downloaded updates:")
For $I = 0 To $searchResult.Updates.Count - 1
    $update = $searchResult.Updates.Item($I)
    If $update.IsDownloaded Then
        ConsoleWrite($I + 1 & "> " & $update.Title & @CR)
    EndIf
Next

$updatesToInstall = ObjCreate("Microsoft.update.UpdateColl")

ConsoleWrite(@CRLF & "Creating collection of downloaded updates to install:")
For $I = 0 To $searchResult.Updates.Count - 1
    $update = $searchResult.Updates.Item($I)
    If $update.IsDownloaded = True Then
        ConsoleWrite($I + 1 & "> adding: " & $update.Title & @CR)
        $updatesToInstall.Add($update)
    EndIf
Next

ConsoleWrite(@CRLF & "Installing updates...")
$installer = $updateSession.CreateUpdateInstaller()
$installer.Updates = $updatesToInstall
If $updatesToInstall.Count > 0 Then
    $installationResult = $installer.Install()
    ;Output results of install
    ConsoleWrite("Installation Result: " & $installationResult.ResultCode)
    ConsoleWrite("Listing of updates installed " & "and individual installation results:")
    For $I = 0 To $updatesToInstall.Count - 1
        ConsoleWrite($I + 1 & "> " & $updatesToInstall.Item($I).Title & ": " & $installationResult.GetUpdateResult($I).ResultCode & @CR)
    Next
Else
    ConsoleWrite(@CRLF & "Nothing to install" & @CRLF)
EndIf

EDIT: You were not adding to the $updatestoinstall. You would have gotten this same error (even with the fix of 'True' instead of '1') if there were no updates to install. This simple count check pre-install will take care of that issue as well.

Edited by danwilli

Share this post


Link to post
Share on other sites

Sometimes when forum server lags at time of saving my post I created duplicated posts too.

But everytime I immediatelly delete my second duplicate post

and I have never accidentaly created more than two or three posts.

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  
Followers 0