cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
KellyF
Level 9

Agent invocation from .NET

We've had a couple people ask about how to invoke the agent within .NET and more specifically for a bit of sample code.

First, for those who've asked, no we do not yet have an Agent written in managed code, so you'll have to invoke it via COM interop from your .NET apps. I also cannot give any sort of timeframe for having an agent written in managed code.

Second, the following two posts include used within MS VS.NET to invoke the component. The first is in VB.NET, the second is C#.NET. They're only code snippets and not complete projects. It's not intended to be a complete application (no try/catch blocks, etc.) but it hopefully will demonstrate the code which can invoke the Agent.

KellyF
0 Kudos

(2) Replies
KellyF
Level 9

NOTE: As mentioned earlier, the agent can currently only be invoked via COM interop (there is no managed code version of the agent yet).

Pre-work
Assuming Visual Studio .NET, you need to add a reference to the Agent via COM interop. You can do this under the View menu by clicking "Add Reference", then choosing the "COM" tab. Once the window is refreshed, scroll down the list until you see the "DW UpdateService 1.0 Type Library", highlight it and click the select button. This adds a reference to your project called "DWUpdateServiceLib".

Once you've added the reference, you're ready to use the object in your project.

' Declarations section
' Note: Change the Product Code below to match the one you've registered with the Update Service, if you do not,
' you'll receive an error 13000 indicating the Update Service doesn't recognize the product.
Const strProductCode As String = "{212E9AE5-23EE-4CA9-8E74-2F31CBFC6EA6}"

' Instantiate the Update Service Agent for later use in application startup or under the "Check for Updates" menu
Dim objUSAgent As New DWUpdateServiceLib.Agent

Using AppUpdate


To check for updates on application startup, you can add this following snippet to your form_Load or sub_main (however you start your app).
' This is the preferred API to check for updates on application start. It automatically checks for a network connection.
objUSAgent.AppUpdate(strProductCode, DWUpdateServiceLib.RunType.AppStart)

To check for updates from a "Check for Updates" menu, you simply change the event type to AppMenu as in below
objUSAgent.AppUpdate(strProductCode, DWUpdateServiceLib.RunType.AppMenu)

Using AutoUpdate
' AutoUpdate requires that we check for a network connection before attempting anything
If (objUSAgent.IsConnected()) Then
If (objUSAgent.AutoUpdate(strProductCode, False)) Then
' Update is downloading and installing.
' We can close down our application here as the agent has taken over the
' download process. When the update is finished, it raises the
' UpdateComplete event if we should wish to continue running and close down
' at that point. Either way, we must close down for the update to be
' installed.

Else
' No updates available, we can continue normal startup
End If
End If
0 Kudos
KellyF
Level 9

NOTE: As mentioned earlier, the agent can currently only be invoked via COM interop (there is no managed code version of the agent yet).

Pre-work
Assuming Visual Studio .NET, you need to add a reference to the Agent via COM interop. You can do this under the View menu by clicking "Add Reference", then choosing the "COM" tab. Once the window is refreshed, scroll down the list until you see the "DW UpdateService 1.0 Type Library", highlight it and click the select button. This adds a reference to your project called "DWUpdateServiceLib".

Once you've added the reference, you're ready to use the object in your project.

// Add these following lines to your class variable declaration section
// Note: Change the Product Code below to match the one you've registered with the Update Service, if you do not,
// you'll receive an error 13000 indicating the Update Service doesn't recognize the product.
private const string strProductCode = "{212E9AE5-23EE-4CA9-8E74-2F31CBFC6EA6}";
private DWUpdateServiceLib.Agent Class objUSAgent = null;

// Instantiate the Update Service Agent for later use in application startup or under the "Check for Updates" menu
// For the simple example, I set this in the Form1_Load() method
objUSAgent = new DWUpdateServiceLib.AgentClass();


Using AppUpdate
To check for updates on application startup, you can add this following snippet to your form_Load.
' This is the preferred API to check for updates on application start. It automatically checks for a network connection.
objUSAgent.AppUpdate (strProductCode,DWUpdateServiceLib.RunType.AppStart);

To check for updates from a "Check for Updates" menu, you simply change the event type to AppMenu as in below
objUSAgent.AppUpdate (strProductCode,DWUpdateServiceLib.RunType.AppMenu);
0 Kudos