Jump to content

COM object not reporting error


haputanlas
 Share

Recommended Posts

Hello Everyone,

I am trying to use Microsoft's Windows Update API (COM Based) to uninstall a specific update automatically. However, I am using their examples to write the following script and I am receiving an error. Unfortunately, that error is not being reported at all (It's blank). I'm not sure if it's not being reported in AutoIt or if this would also be the case with other languages.

Here is the error:

>"G:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "G:\Documents and Settings\Justin\My Documents\test.au3" /autoit3dir "G:\Program Files\AutoIt3" /UserParams

+>16:17:20 Starting AutoIt3Wrapper v.2.0.0.1 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 2 CPU:X86 OS:X86)

>Running AU3Check (1.54.14.0) from:G:\Program Files\AutoIt3

+>16:17:20 AU3Check ended.rc:0

>Running:(3.3.0.0):G:\Program Files\AutoIt3\autoit3.exe "G:\Documents and Settings\Justin\My Documents\test.au3"

G:\Documents and Settings\Justin\My Documents\test.au3 (21) : ==> The requested action with this object has failed.:

$uninstallResult = $updater.Uninstall()

$uninstallResult = $updater.Uninstall()^ ERROR

->16:17:24 AutoIT3.exe ended.rc:1

+>16:17:25 AutoIt3Wrapper Finished

>Exit code: 1 Time: 4.933

And here is the actual code:

#NoTrayIcon
GUISetIcon("nc.ico")

;Uninstall KB956572 Patch
$updateSession = ObjCreate("Microsoft.Update.Session")
$updateSearcher = $updateSession.CreateUpdateSearcher()
$searchResult = $updateSearcher.Search("Type='Software'")
$updateToUninstall = ObjCreate("Microsoft.Update.UpdateColl")

$updateMissing = True
For $i = 0 To ($searchResult.Updates.Count - 1)
    $update = $searchResult.Updates.Item($i)
    If $update.Title = "Security Update for Windows XP (KB956572)" Then
        If $update.IsInstalled = False Then
            MsgBox(0, "Patch is not installed!", "KB956572 is not installed.")
            $updateMissing = False
        ElseIf $update.IsInstalled = True Then
            $updater = $updateSession.CreateUpdateInstaller()
            $updateToUninstall.Add($update)
            $updater.Updates = $updateToUninstall
            $uninstallResult = $updater.Uninstall()
            MsgBox(0, "Failed", $uninstallResult)

            $updateMissing = False
            MsgBox(0, "KB956572 - Uninstalled", "The patch has been uninstalled - " & $update.Title)
        Else
            $updateMissing = True
            MsgBox(0, "Patch Info", "This patch does not exist! - KB956572")
        EndIf
    EndIf
Next

If $updateMissing = True Then
    MsgBox(0, "Error", "The Patch you are looking for does not exist!")
EndIf
Link to comment
Share on other sites

COM error reporting varies with different COM objects (or APIs) and checking for COM errors varies by language used as well.

You might be having similar problem as I. I've worked with MS Word COM object to automate some tasks and if the API operation fails, your script/code will not be notified of the failure, and either an exception is thrown that terminates your app or something erratic happens, I forget.

I worked around my problem by using JScript as the language to access the COM object. I was originally using VBScript but ported over to JScript. JScript, like Javascript, has very nice try/catch exception/error handling, such that if the COM object fails and fails to notify your script (via return value, etc.), then the try/catch block will at least catch the failure.

I don't really use AutoIt language itself, just the COM API, so not sure if AutoIt language has such try/catch error handling facility. If it does, you should make your COM calls within the "try" block and check and handle errors under the "catch" block. If it doesn't you might want to try a different language like JScript (or C++, .NET/C#/VB.NET). VBScript won't do either.

Link to comment
Share on other sites

OK, I have been able to get the COM error handling to work properly on my script. However, the error number is 80020009 and the description is a bunch of strange characters that kind of look like WingDings :D

Any other help would be appreciated.

Thanks

Justin

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...