Appx/MSIX Proces information using AutoHotKey 2

Post your working scripts, libraries and tools.
Ferry
Posts: 13
Joined: 10 Jul 2014, 15:55

Appx/MSIX Proces information using AutoHotKey 2

Post by Ferry » 20 Mar 2023, 08:05

If you are looking for a way to get AppX/MSIX information for your product running within an AppX/MSIX environment (Windows 10 or 11) you can use this AutoHotKey v2 script as a starting point. The script will retrieve information like the Application Id (AppId) so you know what entry point (shortcut) is used when it is started.
Other information that will be collected are:

AppUserModelId
PackagePath
PackageFullName
PackageFamilyName
PackageName
PublisherId

Running this script outside the Appx/MSIX environment wil display empty values so you need to run it inside the AppX/MSIX environment. One easy way of doing this is to get the Microsoft MSIX Packaging Tool from the Microsoft Windows Store (the tool is free) and (re)package your compiled script or you can copy both the AutoHotkey64.exe and this script with the same name (AutoHotkey64.ahk) and place both of them in the same folder and create one or more entry points (shortcuts) for the AutoHotkey64.exe when creating a new MSIX Package.

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance off
#NoTrayIcon

; --------------------------------------------------------------- Collect AppX/MSIX Package Information ---------------------------------------------------------------
AppUserModelId := GetCurrentApplicationUserModelId(256)
If AppUserModelId
	{
	AppUserModelIdAppiD := StrSplit(AppUserModelId, "!")
	AppId := AppUserModelIdAppiD[2]
	}
Else
	AppId := ""	
PackagePath := GetCurrentPackagePath(256)
PackageFullName := GetCurrentPackageFullName(128)
PackageFamilyName := GetCurrentPackageFamilyName(128)
If PackageFamilyName
	{
	PackageNamePublisherId := StrSplit(PackageFamilyName, "_")
	PackageName := PackageNamePublisherId[1]
	PublisherId := PackageNamePublisherId[2]
	}
Else
	{
	PackageName := ""
	PublisherId := ""
	}

MsgBox "PackagePath: " PackagePath "`nPackageFullName: " PackageFullName "`nPackageName: " PackageName "`nPublisherId: " PublisherId "`nPackageFamilyName: " PackageFamilyName "`nAppUserModelId: " AppUserModelId "`n`nApplication Id: " AppId, "MSIX Package Information", "iconi"
ExitApp 0

; --------------------------------------------------------------- Functions for Collecting AppX/MSIX Package Information ---------------------------------------------------------------
GetCurrentPackagePath(pathLength)
	{
	GetCurrentPackagePath := Buffer(pathLength, 0) 
	DllCall("GetCurrentPackagePath", "Wstr", pathLength, "Ptr", GetCurrentPackagePath)
	GetPackagePath := StrGet(GetCurrentPackagePath)
	Return GetPackagePath
	}
GetCurrentPackageFullName(packageFullNameLength)
	{
	GetCurrentPackageFullName := Buffer(packageFullNameLength, 0) 
	DllCall("GetCurrentPackageFullName", "Wstr", packageFullNameLength, "Ptr", GetCurrentPackageFullName)
	GetPackageFullName := StrGet(GetCurrentPackageFullName)
	Return GetPackageFullName
	}
GetCurrentPackageFamilyName(packageFamilyNameLength)
	{
	GetCurrentPackageFamilyName := Buffer(packageFamilyNameLength, 0) 
	DllCall("GetCurrentPackageFamilyName", "Wstr", packageFamilyNameLength, "Ptr", GetCurrentPackageFamilyName)
	GetPackageFamilyName := StrGet(GetCurrentPackageFamilyName)
	Return GetPackageFamilyName
	}
GetCurrentApplicationUserModelId(applicationUserModelIdLength)
	{
	GetCurrentApplicationUserModelId := Buffer(applicationUserModelIdLength, 0)
	DllCall("GetCurrentApplicationUserModelId", "Wstr", applicationUserModelIdLength, "Ptr", GetCurrentApplicationUserModelId)
	GetAppUserModelId := StrGet(GetCurrentApplicationUserModelId)
	Return GetAppUserModelId
	}
Information:
https://learn.microsoft.com/en-us/windows/win32/api/appmodel/
https://learn.microsoft.com/en-us/windows/msix/overview

Return to “Scripts and Functions (v2)”