cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
NealC804
Level 8

Update Ready but user is not!

I'm using the code just like in the ISUS docs as shown at the bottom. In the OnDownloadComplete event I prompt the user just like in the docs sample. The problem is, "what if" the user says "No, I'm not ready" and they want to update after they are done with something, on the next program run, etc. Obviously the Update won't download again, so how do we CHECK if an update exists, already downloaded, but hasn't been installed yet?


Const pszProductCode = "{E5D5D9E8-178A-4312-B9C0-094442490497}"
Dim UpdateAgent As Agent
Dim UpdateCollection As Updates
Dim WithEvents UpdateInstance As Update

Private Sub CheckForUpdates()
Set UpdateAgent = New Agent

If UpdateAgent.IsConnected Then
Set UpdateCollection = UpdateAgent.EnumUpdates(pszProductCode)
For iIndex = 1 To UpdateCollection.Count
Set UpdateInstance = UpdateCollection.Item(iIndex)
If (UpdateInstance.IsNextUse = True) Then
If (UpdateInstance.Download(True) = True) Then
UpdateInstance.Execute
End If
End If
Next
End If

End Sub

Public Sub Form_Load()
CheckForUpdates

End Sub

Private Sub UpdateInstance_OnDownloadBegin()
'MsgBox "OnDownloadBegin"
End Sub

Private Sub UpdateInstance_OnDownloadComplete(ByVal nResultCode As Long)
'MsgBox "OnDownloadComplete"
If nResultCode <> 0 Then
MsgBox UpdateInstance.GetErrorDescription(1)
Else
If MsgBox("An Update has been downloaded, do you want to install?", vbYesNo, "Update Available") = vbYes Then
UpdateInstance.Execute
End If
End If
End Sub
Private Sub UpdateInstance_OnProgressChanged(ByVal nBytes As Long, ByVal nPercent As Long,
ByVal strTransferRate As String, ByVal strTimeRemaining As String)
nBytes = Round(nBytes / 1024)
'Write these values to a label in the form
lblStatus.Caption = "Percent complete: " & nPercent & "%" & vbNewLine _
& "Bytes downloaded: " & nBytes & " kb" & vbNewLine _
& "Transfer Rate: " & strTransferRate & vbNewLine _
& "Time left: " & strTimeRemaining
End Sub

Private Sub UpdateInstance_OnUpdateBegin()
'MsgBox "OnUpdateBegin"
End Sub

Private Sub UpdateInstance_OnUpdateComplete(ByVal nResultCode As Long)
'MsgBox "OnUpdateComplete"
End Sub
0 Kudos
(5) Replies
KellyF
Level 9

Neal,

As the update was not applied, it will be re-detected as available when the EnumUpdates is called. Because you're using the Update.Download() API, the method will return true immediately as the download was already updated. So you don't need to check for its existence manually as the check is done as part of the Download() call...

KellyF

PS. More info can be found in the help documents under
Update Service Reference
APIs
Windows Agent
Update Service Objects
Update
Methods
0 Kudos
NealC804
Level 8

Thanks Kelly!

One other question:

I also publish messages, which are .htm files. The code I use in the message above is only to retrieve software updates, so I check for IsNextUse to capture my critical updates. I'd like to see if there are any messages then display these to the user if they opt to view them. In either case, I need to mark them as "read" so they don't get this every time, such as when clicking "Hide" in the Update Manager if it shows in the list there. How do we go about this?

So in other words, determine if messages are available, if so, display it to the user THEN hide it so it doesn't continuously show to the user as a message available?

Same with the software update, what if they don't want to install it? I don't want them getting prompted every time the program runs which WILL happen according to your response as the update is ready(downloaded). What if they don't want to install it, ever? How do we "hide" the update in this case?

Thanks!
0 Kudos
KellyF
Level 9

Check out conditions.

KellyF
0 Kudos
NealC804
Level 8

In the API? I need to do this via VB6 code.
0 Kudos
KellyF
Level 9

Sorry, it's been a bit hectic recently, hence the short response before... check out the help item "Create Update Conditions View". It'll describe how you can use custom VB scripts which will be executed to check for particular conditions on the client. You can then manage your items in the way you best see fit.
0 Kudos