This script will start Notepad.exe and uses the PID to get the AppX Package information when it is started on a Windows 10 or Windows 11 operating system. If no PID information is used it will try to get this information for its own process.
https://learn.microsoft.com/en-us/windows/msix/msix-container
https://learn.microsoft.com/en-us/windows/win32/api/appmodel
Code: Select all
Run, Notepad.exe,, UseErrorLevel, PID
hProc := OpenProcess(PID)
PackageFullName := GetPackageFullName(hProc)
PackagePath := GetPackagePath(PackageFullName)
PackageFamilyName := GetPackageFamilyName(hProc)
If PackageFamilyName
{
StringSplit, PackageNamePublisherId, PackageFamilyName, _
PackageName := PackageNamePublisherId1
PublisherId := PackageNamePublisherId2
}
Else
{
PublisherId =
PackageName =
}
AppUserModelId := GetApplicationUserModelId(hProc)
If AppUserModelId
{
StringSplit, AppUserModelIdAppiD, AppUserModelId, !
AppID := AppUserModelIdAppiD2
}
Else
AppID =
MsgBox, PackagePath = %PackagePath%`nPackageFullName = %PackageFullName%`nPackageName = %PackageName%`nPublisherId = %PublisherId%`nPackageFamilyName = %PackageFamilyName%`nAppUserModelId = %AppUserModelId%`nAppId = %AppID%
ExitApp
; --------------------------------------------------------------- Functions for Collecting AppX/MSIX Package Information ---------------------------------------------------------------
OpenProcess(PID)
{
PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
hProc := DllCall("OpenProcess", "UInt", PROCESS_QUERY_LIMITED_INFORMATION, "UInt", 0, "Ptr", PID, "Ptr")
Return hProc
}
GetPackagePath(PackageFullName)
{
pathLength = 256
bytes_per_char := A_IsUnicode ? 2 : 1
GetCurrentPackagePathLength := pathLength * bytes_per_char
VarSetCapacity(GetCurrentPackagePath, GetCurrentPackagePathLength)
If PackageFullName
DllCall("GetPackagePathByFullName", "Ptr", &PackageFullName, "Wstr", GetCurrentPackagePathLength, "Ptr", &GetCurrentPackagePath)
Else
DllCall("GetCurrentPackagePath", "Wstr", GetCurrentPackagePathLength, "Ptr", &GetCurrentPackagePath)
PackagePath := StrGet(&GetCurrentPackagePath)
Return PackagePath
}
GetPackageFullName(hProc)
{
packageFullNameLength = 128
bytes_per_char := A_IsUnicode ? 2 : 1
GetCurrentPackageFullNameLength := packageFullNameLength * bytes_per_char
VarSetCapacity(GetCurrentPackageFullName, GetCurrentPackageFullNameLength)
If hProc
DllCall("GetPackageFullName", "Uint", hProc, "Wstr", GetCurrentPackageFullNameLength, "Ptr", &GetCurrentPackageFullName)
Else
DllCall("GetCurrentPackageFullName", "Wstr", GetCurrentPackageFullNameLength, "Ptr", &GetCurrentPackageFullName)
PackageFullName := StrGet(&GetCurrentPackageFullName)
Return PackageFullName
}
GetPackageFamilyName(hProc)
{
packageFamilyNameLength = 128
bytes_per_char := A_IsUnicode ? 2 : 1
GetCurrentPackageFamilyNameLength := packageFamilyNameLength * bytes_per_char
VarSetCapacity(GetCurrentPackageFamilyName, GetCurrentPackageFamilyNameLength)
If hProc
DllCall("GetPackageFamilyName", "Uint", hProc, "Wstr", GetCurrentPackageFamilyNameLength, "Ptr", &GetCurrentPackageFamilyName)
Else
DllCall("GetCurrentPackageFamilyName", "Wstr", GetCurrentPackageFamilyNameLength, "Ptr", &GetCurrentPackageFamilyName)
PackageFamilyName := StrGet(&GetCurrentPackageFamilyName)
Return PackageFamilyName
}
GetApplicationUserModelId(hProc)
{
applicationUserModelIdLength = 256
bytes_per_char := A_IsUnicode ? 2 : 1
GetCurrentApplicationUserModelIdLength := applicationUserModelIdLength * bytes_per_char
VarSetCapacity(GetCurrentApplicationUserModelId, GetCurrentApplicationUserModelIdLength)
If hProc
DllCall("GetApplicationUserModelId", "Uint", hProc, "Wstr", GetCurrentApplicationUserModelIdLength, "Ptr", &GetCurrentApplicationUserModelId)
Else
DllCall("GetCurrentApplicationUserModelId", "Wstr", GetCurrentApplicationUserModelIdLength, "Ptr", &GetCurrentApplicationUserModelId)
AppUserModelId := StrGet(&GetCurrentApplicationUserModelId)
Return AppUserModelId
}