dcsimg
Results 1 to 2 of 2

Thread: VB.NET and wuapi.dll

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2012
    Posts
    1

    VB.NET and wuapi.dll

    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.

  2. #2
    New Member
    Join Date
    Mar 2018
    Posts
    1

    Re: VB.NET and wuapi.dll

    Quote Originally Posted by TheFork View Post

    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.
    Hey TheFork,

    This answer probably comes to you 6 years too late, but in case anyone else stumbles upon this, I've just gone through the same thing, and found the issue to be that the windows update agent was not up to date. After installing the latest version of windows update agent 3.0, the problem was resolved.

    You can do this by opening windows update (assuming we're talking about XP) and clicking the update button, or by downloading the standalone installer from microsoft.

    Regards,
    Joey

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width