description: Learn how to get certain kinds of activation info for packaged .NET and C++ desktop (Win32) apps title: Get activation info for packaged apps ms.date: 09/17/2020 ms.topic: article keywords: windows 10, uwp ms.localizationpriority: medium
Starting in Windows 10, version 1809, packaged desktop apps can call the AppInstance.GetActivatedEventArgs method to retrieve certain kinds of app activation info during startup. For example, you can call this method to get info related to app activation from opening a file, clicking an interactive toast, or using a protocol. Starting in Windows 10, version 2004, this feature is also supported in packaged apps with external location (see Grant package identity by packaging with external location).
Note
In addition to retrieving certain types of activation info by using the AppInstance.GetActivatedEventArgs method as described in this article, you can also retrieve activation info for background tasks by defining a COM class. For more info, see Create and register a winmain COM background task.
The following code example demonstrates how to call the AppInstance.GetActivatedEventArgs method from the Main function in a Windows Forms app. For each activation type your app supports, cast the args return value to the corresponding event args type. In this code example, the Handlexxx methods are assumed to be dedicated activation handler code that you have defined elsewhere.
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var args = AppInstance.GetActivatedEventArgs();
switch (args.Kind)
{
case ActivationKind.Launch:
HandleLaunch(args as LaunchActivatedEventArgs);
break;
case ActivationKind.ToastNotification:
HandleToastNotification(args as ToastNotificationActivatedEventArgs);
break;
case ActivationKind.VoiceCommand:
HandleVoiceCommand(args as VoiceCommandActivatedEventArgs);
break;
case ActivationKind.File:
HandleFile(args as FileActivatedEventArgs);
break;
case ActivationKind.Protocol:
HandleProtocol(args as ProtocolActivatedEventArgs);
break;
case ActivationKind.StartupTask:
HandleStartupTask(args as StartupTaskActivatedEventArgs);
break;
default:
HandleLaunch(null);
break;
}You can use the AppInstance.GetActivatedEventArgs method to retrieve activation info from the supported set of event args objects listed in the following table. Some of these activation types require the use of a package extension in the package manifest.
ShareTargetActivatedEventArgs activation info is supported only on Windows 10, version 2004, and later. All other activation info types are supported on Windows 10, version 1809, and later.