Skip to content

Instantly share code, notes, and snippets.

@glennsarti
Created July 12, 2019 02:51
Show Gist options
  • Save glennsarti/e3097d0cd4df649eefffa5d63747cfa9 to your computer and use it in GitHub Desktop.
Save glennsarti/e3097d0cd4df649eefffa5d63747cfa9 to your computer and use it in GitHub Desktop.
Activate an AppX program by name
param($AppXID)
$AppXPackage = Get-AppxPackage $AppXID
$AppXManifest = Get-appxpackagemanifest $AppXPackage
$AppXModelID = $AppXPackage.PackageFamilyName + "!" + $AppXManifest.package.applications.application.id
$csharp = @"
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace RunAppX
{
[ComImport, Guid("2e941141-7f97-4756-ba1d-9decde894a3d"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IApplicationActivationManager
{
IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] UInt32 options, [Out] out UInt32 processId);
}
[ComImport, Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C")]
public class ApplicationActivationManager : IApplicationActivationManager
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
public extern IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] UInt32 options, [Out] out UInt32 processId);
}
}
"@
Add-Type -TypeDefinition $csharp
$Manager = new-object RunAppX.ApplicationActivationManager
$Manager.ActivateApplication($AppXModelID, $null, 0, [ref]0) | Out-Null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment