I've been trying to create a console application in VB.NET that downloads and installs Windows Updates. I'm referencing wuapi.dll, and using the code at the following MSDN site as a starting point:

http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

Here is my code:

Code:
Module Module1

    Public updateSession As Object
    Public updateSearcher As Object
    Public searchResult As Object
    Public update As Object
    Public updatesToDownload As Object
    Public downloader As Object
    Public updatesToInstall As Object
    Public strInput As String
    Public installer As Object
    Public installationResult As Object

    Sub Main()

        Try

            updateSession = CreateObject("Microsoft.Update.Session")
            updateSearcher = updateSession.CreateupdateSearcher()

            Console.WriteLine("Searching for updates..." & vbCrLf)

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

            For I = 0 To searchResult.Updates.Count - 1
                update = searchResult.Updates.Item(I)
                Console.WriteLine(I + 1 & "> " & update.Title)
            Next

            If searchResult.Updates.Count = 0 Then
                Console.WriteLine("There are no applicable updates.")
                End
            End If

            Console.WriteLine(searchResult.updates.count & " updates required")

            Console.WriteLine(vbCrLf & "Creating collection of updates to download:")

            updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")

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

            Console.WriteLine(vbCrLf & "Downloading updates...")

            downloader = updateSession.CreateUpdateDownloader()
            downloader.Updates = updatesToDownload
            downloader.Download()

            Console.WriteLine(vbCrLf & "List of downloaded updates:")

            For I = 0 To searchResult.Updates.Count - 1
                update = searchResult.Updates.Item(I)
                If update.IsDownloaded Then
                    Console.WriteLine(I + 1 & "> " & update.Title)
                End If
            Next

            updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")

            Console.WriteLine(vbCrLf & _
            "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
                    Console.WriteLine(I + 1 & "> adding:  " & update.Title)
                    updatesToInstall.Add(update)
                End If
            Next

            Console.WriteLine(vbCrLf & "Would you like to install updates now? (Y/N)")
            strInput = Console.ReadLine()
            Console.WriteLine()

            If (strInput = "N" Or strInput = "n") Then
                End
            ElseIf (strInput = "Y" Or strInput = "y") Then
                Console.WriteLine("Installing updates...")
                installer = updateSession.CreateUpdateInstaller()
                installer.Updates = updatesToInstall
                installationResult = installer.Install()

                'Output results of install
                Console.WriteLine("Installation Result: " & _
                installationResult.ResultCode)
                Console.WriteLine("Reboot Required: " & _
                installationResult.RebootRequired & vbCrLf)
                Console.WriteLine("Listing of updates installed " & _
                 "and individual installation results:")

                For I = 0 To updatesToInstall.Count - 1
                    Console.WriteLine(I + 1 & "> " & _
                    updatesToInstall.Item(I).Title & _
                    ": " & installationResult.GetUpdateResult(I).ResultCode)
                Next
            End If

        Catch ex As Exception
            Console.WriteLine("Caught an exception:" & vbCrLf & ex.Message)
        End Try

    End Sub

End Module
When I run this, it fails at the line that I've highlighted in red. I know this, because I've used console.writeline() to output some debug checkpoints along the way.

The exact error message is:

Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))

I really don't understand what is happening here, and would be extremely grateful if anyone could tell me what I might be doing wrong.

Thanks for any suggestions,

TheFork.