using System; using System.Runtime.InteropServices; using System.Text; namespace Vanara.PInvoke { public static partial class Kernel32 { /// /// The AppPolicyCreateFileAccess enumeration indicates whether a process has full or restricted access to the IO devices (file, file /// stream, directory, physical disk, volume, console buffer, tape drive, communications resource, mailslot, and pipe). /// // typedef enum AppPolicyCreateFileAccess { AppPolicyCreateFileAccess_Full = 0, AppPolicyCreateFileAccess_Limited = 1} // AppPolicyCreateFileAccess; https://msdn.microsoft.com/en-us/library/windows/desktop/mt829654(v=vs.85).aspx [PInvokeData("AppModel.h", MSDNShortId = "mt829654")] public enum AppPolicyCreateFileAccess { /// /// Indicates that the process has full access to the IO devices. This value is expected for a desktop application, or for a /// Desktop Bridge application. /// AppPolicyCreateFileAccess_Full, /// Indicates that the process has limited access to the IO devices. This value is expected for a UWP app. AppPolicyCreateFileAccess_Limited, } /// The AppPolicyProcessTerminationMethod enumeration indicates the method used to end a process. // typedef enum AppPolicyProcessTerminationMethod { AppPolicyProcessTerminationMethod_ExitProcess = 0, // AppPolicyProcessTerminationMethod_TerminateProcess = 1} AppPolicyProcessTerminationMethod; https://msdn.microsoft.com/en-us/library/windows/desktop/mt829659(v=vs.85).aspx [PInvokeData("AppModel.h", MSDNShortId = "mt829659")] public enum AppPolicyProcessTerminationMethod { /// /// Allows DLLs to execute code at shutdown. This value is expected for a desktop application, or for a Desktop Bridge application. /// AppPolicyProcessTerminationMethod_ExitProcess, /// Immediately ends the process. This value is expected for a UWP app. AppPolicyProcessTerminationMethod_TerminateProcess, } /// /// The AppPolicyShowDeveloperDiagnostic enumeration indicates the method used for a process to surface developer information, such /// as asserts, to the user. /// // typedef enum AppPolicyShowDeveloperDiagnostic { AppPolicyShowDeveloperDiagnostic_None = 0, AppPolicyShowDeveloperDiagnostic_ShowUI // = 1} AppPolicyShowDeveloperDiagnostic; https://msdn.microsoft.com/en-us/library/windows/desktop/mt829660(v=vs.85).aspx [PInvokeData("AppModel.h", MSDNShortId = "mt829660")] public enum AppPolicyShowDeveloperDiagnostic { /// Indicates that the process does not show developer diagnostics. This value is expected for a UWP app. AppPolicyShowDeveloperDiagnostic_None, /// /// Indicates that the process shows developer diagnostics UI. This value is expected for a desktop application, or for a Desktop /// Bridge application. /// AppPolicyShowDeveloperDiagnostic_ShowUI, } /// /// The AppPolicyThreadInitializationType enumeration indicates the kind of initialization that should be automatically performed for /// a process when beginthread[ex] creates a thread. /// // typedef enum AppPolicyThreadInitializationType { AppPolicyThreadInitializationType_None = 0, // AppPolicyThreadInitializationType_InitializeWinRT = 1} AppPolicyThreadInitializationType; https://msdn.microsoft.com/en-us/library/windows/desktop/mt829661(v=vs.85).aspx [PInvokeData("AppModel.h", MSDNShortId = "mt829661")] public enum AppPolicyThreadInitializationType { /// Indicates that no initialization should be performed. AppPolicyThreadInitializationType_None, /// Indicates that Windows Runtime initialization should be performed. AppPolicyThreadInitializationType_InitializeWinRT, } /// /// Specifies the processor architectures supported by a package. /// // https://docs.microsoft.com/en-us/windows/desktop/api/appxpackaging/ne-appxpackaging-appx_package_architecture typedef enum // APPX_PACKAGE_ARCHITECTURE { APPX_PACKAGE_ARCHITECTURE_X86 , APPX_PACKAGE_ARCHITECTURE_ARM , APPX_PACKAGE_ARCHITECTURE_X64 , // APPX_PACKAGE_ARCHITECTURE_NEUTRAL , APPX_PACKAGE_ARCHITECTURE_ARM64 } ; [PInvokeData("appxpackaging.h", MSDNShortId = "8BC7ABF0-448F-4405-AA82-49C6DB3F230C")] public enum APPX_PACKAGE_ARCHITECTURE { /// The x86 processor architecture. APPX_PACKAGE_ARCHITECTURE_X86 = 0, /// The ARM processor architecture. APPX_PACKAGE_ARCHITECTURE_ARM = 5, /// The x64 processor architecture. APPX_PACKAGE_ARCHITECTURE_X64 = 9, /// Any processor architecture. APPX_PACKAGE_ARCHITECTURE_NEUTRAL = 11, /// The 64-bit ARM processor architecture. APPX_PACKAGE_ARCHITECTURE_ARM64 = 12, } /// Specifies how packages are to be processed. // https://docs.microsoft.com/en-us/windows/desktop/appxpkg/package-constants [PInvokeData("", MSDNShortId = "72E565C3-6CFD-47E3-8BAC-17D6E86B99DA")] [Flags] public enum PACKAGE_FLAGS : uint { /// The maximum number of apps in a package. PACKAGE_APPLICATIONS_MAX_COUNT = 100, /// The minimum number of apps in a package. PACKAGE_APPLICATIONS_MIN_COUNT = 0, /// The maximum number of resource packages a package can have. PACKAGE_FAMILY_MAX_RESOURCE_PACKAGES = 512, /// The minimum number of resource packages a package can have. PACKAGE_FAMILY_MIN_RESOURCE_PACKAGES = 0, /// /// Process all packages in the dependency graph. This is equivalent to PACKAGE_FILTER_HEAD | PACKAGE_FILTER_DIRECT. Note: /// PACKAGE_FILTER_ALL_LOADED may be altered or unavailable for releases after Windows 8.1. Instead, use PACKAGE_FILTER_HEAD | PACKAGE_FILTER_DIRECT. /// PACKAGE_FILTER_ALL_LOADED = 0x00000000, /// Process bundle packages in the package graph. PACKAGE_FILTER_BUNDLE = 0x00000080, /// Process the directly dependent packages of the head (first) package in the dependency graph. PACKAGE_FILTER_DIRECT = 0x00000020, /// Process the first package in the dependency graph. PACKAGE_FILTER_HEAD = 0x00000010, /// Process bundle packages in the package graph. PACKAGE_FILTER_OPTIONAL = 0x00020000, /// Process resource packages in the package graph. PACKAGE_FILTER_RESOURCE = 0x00000040, /// The maximum size of a package graph. PACKAGE_GRAPH_MAX_SIZE = (1 + PACKAGE_MAX_DEPENDENCIES + PACKAGE_FAMILY_MAX_RESOURCE_PACKAGES), /// The minimum size of a package graph. PACKAGE_GRAPH_MIN_SIZE = 1, /// Retrieve basic information. PACKAGE_INFORMATION_BASIC = 0x00000000, /// Retrieve full information. PACKAGE_INFORMATION_FULL = 0x00000100, /// The maximum number of packages a package depends on. PACKAGE_MAX_DEPENDENCIES = 128, /// The minimum number of packages a package depends on. PACKAGE_MIN_DEPENDENCIES = 0, /// The package is a bundle package. PACKAGE_PROPERTY_BUNDLE = 0x00000004, /// The package was registered with the DeploymentOptions enumeration. PACKAGE_PROPERTY_DEVELOPMENT_MODE = 0x00010000, /// The package is a framework. PACKAGE_PROPERTY_FRAMEWORK = 0x00000001, /// The package is an optional package. PACKAGE_PROPERTY_OPTIONAL = 0x00000008, /// The package is a resource package. PACKAGE_PROPERTY_RESOURCE = 0x00000002, } /// /// Specifies the origin of a package. /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/ne-appmodel-packageorigin typedef enum PackageOrigin { // PackageOrigin_Unknown , PackageOrigin_Unsigned , PackageOrigin_Inbox , PackageOrigin_Store , PackageOrigin_DeveloperUnsigned , // PackageOrigin_DeveloperSigned , PackageOrigin_LineOfBusiness } ; [PInvokeData("appmodel.h", MSDNShortId = "0CB9CE97-8A54-4BE7-B054-00F29D36CAB2")] public enum PackageOrigin { /// The package's origin is unknown. PackageOrigin_Unknown, /// The package originated as unsigned. PackageOrigin_Unsigned, /// The package was included inbox. PackageOrigin_Inbox, /// The package originated from the Windows Store. PackageOrigin_Store, /// The package originated as developer unsigned. PackageOrigin_DeveloperUnsigned, /// The package originated as developer signed. PackageOrigin_DeveloperSigned, /// The package originated as a line-of-business app. PackageOrigin_LineOfBusiness, } /// Indicates the type of folder path to retrieve in a query for the path or other info about a package. /// /// An application has a mutable install folder if it uses the windows.mutablePackageDirectories extension in its package manifest. /// This extension specifies a folder under the %ProgramFiles%\ModifiableWindowsApps path where the contents of the application's /// install folder are projected so that users can modify the installation files. This feature is currently available only for /// certain types of desktop PC games that are published by Microsoft and our partners, and it enables these types of games to /// support mods. /// // https://docs.microsoft.com/en-us/windows/win32/api/appmodel/ne-appmodel-packagepathtype typedef enum PackagePathType { // PackagePathType_Install, PackagePathType_Mutable, PackagePathType_Effective } ; [PInvokeData("appmodel.h")] public enum PackagePathType { /// Retrieve the package path in the original install folder for the application. PackagePathType_Install, /// /// Retrieve the package path in the mutable install folder for the application, if the application is declared as mutable in /// the package manifest. /// PackagePathType_Mutable, /// /// Retrieve the package path in the mutable folder if the application is declared as mutable in the package manifest, or in the /// original install folder if the application is not mutable. /// PackagePathType_Effective } /// /// Retrieves a value indicating whether a process has full or restricted access to the IO devices (file, file stream, directory, /// physical disk, volume, console buffer, tape drive, communications resource, mailslot, and pipe). /// /// A handle that identifies the access token for a process. /// /// A pointer to a variable of the AppPolicyCreateFileAccess enumerated type. When the function returns successfully, the /// variable contains an enumerated constant value indicating whether the process has full or restricted access to the IO devices. /// /// /// If the function succeeds, the function returns ERROR_SUCCESS. /// /// If no known create file access policy was found for the process token, the function raises a STATUS_ASSERTION_FAILURE exception /// and returns ERROR_NOT_FOUND. /// /// If either processToken or policy are null, the function returns ERROR_INVALID_PARAMETER. /// // LONG WINAPI AppPolicyGetCreateFileAccess( _In_ HANDLE processToken, _Out_ AppPolicyCreateFileAccess *policy); https://msdn.microsoft.com/en-us/library/windows/desktop/mt829655(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("AppModel.h", MSDNShortId = "mt829655")] public static extern Win32Error AppPolicyGetCreateFileAccess(HTOKEN processToken, out AppPolicyCreateFileAccess policy); /// Retrieves the method used to end a process. /// A handle that identifies the access token for a process. /// /// A pointer to a variable of the AppPolicyProcessTerminationMethod enumerated type. When the function returns successfully, /// the variable contains a value indicating the method used to end the process. /// /// /// If the function succeeds, the function returns ERROR_SUCCESS. /// /// If no known create file access policy was found for the process token, the function raises a STATUS_ASSERTION_FAILURE exception /// and returns ERROR_NOT_FOUND. /// /// If either processToken or policy are null, the function returns ERROR_INVALID_PARAMETER. /// // LONG WINAPI AppPolicyGetProcessTerminationMethod( _In_ HANDLE processToken, _Out_ AppPolicyProcessTerminationMethod *policy); https://msdn.microsoft.com/en-us/library/windows/desktop/mt829656(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("AppModel.h", MSDNShortId = "mt829656")] public static extern Win32Error AppPolicyGetProcessTerminationMethod(HTOKEN processToken, out AppPolicyProcessTerminationMethod policy); /// Retrieves the method used for a process to surface developer information, such as asserts, to the user. /// A handle that identifies the access token for a process. /// /// A pointer to a variable of the AppPolicyShowDeveloperDiagnostic enumerated type. When the function returns successfully, /// the variable contains a value indicating the method used for the process to surface developer information, such as asserts, to /// the user. /// /// /// If the function succeeds, the function returns ERROR_SUCCESS. /// /// If no known create file access policy was found for the process token, the function raises a STATUS_ASSERTION_FAILURE exception /// and returns ERROR_NOT_FOUND. /// /// If either processToken or policy are null, the function returns ERROR_INVALID_PARAMETER. /// // LONG WINAPI AppPolicyGetShowDeveloperDiagnostic( _In_ HANDLE processToken, _Out_ AppPolicyShowDeveloperDiagnostic *policy); https://msdn.microsoft.com/en-us/library/windows/desktop/mt829657(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("AppModel.h", MSDNShortId = "mt829657")] public static extern Win32Error AppPolicyGetShowDeveloperDiagnostic(HTOKEN processToken, out AppPolicyShowDeveloperDiagnostic policy); /// /// Retrieves the kind of initialization that should be automatically performed for a process when beginthread[ex] creates a thread. /// /// A handle that identifies the access token for a process. /// /// A pointer to a variable of the AppPolicyThreadInitializationType enumerated type. When the function returns successfully, /// the variable contains a value indicating the kind of initialization that should be automatically performed for the process when /// beginthread[ex] creates a thread. /// /// /// If the function succeeds, the function returns ERROR_SUCCESS. /// /// If no known create file access policy was found for the process token, the function raises a STATUS_ASSERTION_FAILURE exception /// and returns ERROR_NOT_FOUND. /// /// If either processToken or policy are null, the function returns ERROR_INVALID_PARAMETER. /// // LONG WINAPI AppPolicyGetThreadInitializationType( _In_ HANDLE processToken, _Out_ AppPolicyThreadInitializationType *policy); https://msdn.microsoft.com/en-us/library/windows/desktop/mt829658(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("AppModel.h", MSDNShortId = "mt829658")] public static extern Win32Error AppPolicyGetThreadInitializationType(HTOKEN processToken, out AppPolicyThreadInitializationType policy); /// /// Closes a reference to the specified package information. /// /// /// Type: PACKAGE_INFO_REFERENCE /// A reference to package information. /// /// /// Type: LONG /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-closepackageinfo LONG ClosePackageInfo( // PACKAGE_INFO_REFERENCE packageInfoReference ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("appmodel.h", MSDNShortId = "BA84FB47-F241-4120-9441-7E1149F68738")] public static extern Win32Error ClosePackageInfo(PACKAGE_INFO_REFERENCE packageInfoReference); /// /// Finds the packages with the specified family name for the current user. /// /// /// Type: PCWSTR /// The package family name. /// /// /// Type: UINT32 /// /// The package constants that specify how package information is retrieved. All package constants except /// PACKAGE_FILTER_ALL_LOADED are supported. /// /// /// /// Type: UINT32* /// A pointer to a variable that holds the number of package full names that were found. /// /// First you pass NULL to packageFullNames to get the number of package full names that were found. You use this number to /// allocate memory space for packageFullNames. Then you pass the address of this memory space to fill packageFullNames. /// /// /// /// Type: PWSTR* /// A pointer to memory space that receives the strings of package full names that were found. /// /// /// Type: UINT32* /// A pointer to a variable that holds the number of characters in the string of package full names. /// /// First you pass NULL to buffer to get the number of characters. You use this number to allocate memory space for buffer. /// Then you pass the address of this memory space to fill buffer. /// /// /// /// Type: WCHAR* /// A pointer to memory space that receives the string of characters for all of the package full names. /// /// /// Type: UINT32* /// A pointer to memory space that receives the package properties for all of the packages that were found. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// One or more buffer is not large enough to hold the data. The required size is specified by either count or buffer. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-findpackagesbypackagefamily LONG // FindPackagesByPackageFamily( PCWSTR packageFamilyName, UINT32 packageFilters, UINT32 *count, PWSTR *packageFullNames, UINT32 // *bufferLength, WCHAR *buffer, UINT32 *packageProperties ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("appmodel.h", MSDNShortId = "D52E98BD-726F-4AC0-A034-02896B1D1687")] public static extern Win32Error FindPackagesByPackageFamily(string packageFamilyName, PACKAGE_FLAGS packageFilters, ref uint count, IntPtr packageFullNames, ref uint bufferLength, IntPtr buffer, IntPtr packageProperties); /// /// Constructs an application user model ID from the package family name and the package relative application ID (PRAID). /// /// /// Type: PCWSTR /// The package family name. /// /// /// Type: PCWSTR /// The package-relative app ID (PRAID). /// /// /// Type: UINT32* /// /// A pointer to a variable that holds the number of characters ( WCHAR s) in the app user model ID string, which includes the null-terminator. /// /// /// First you pass NULL to applicationUserModelId to get the number of characters. You use this number to allocate memory /// space for applicationUserModelId. Then you pass the address of this memory space to fill applicationUserModelId. /// /// /// /// Type: PWSTR /// A pointer to memory space that receives the app user model ID string, which includes the null-terminator. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// The packageFamilyName or packageRelativeApplicationId parameter isn't valid. /// /// /// ERROR_INSUFFICIENT_BUFFER /// /// The buffer specified by applicationUserModelId is not large enough to hold the data; the required buffer size, in WCHARs, is /// stored in the variable pointed to by applicationUserModelIdLength. /// /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-formatapplicationusermodelid LONG // FormatApplicationUserModelId( PCWSTR packageFamilyName, PCWSTR packageRelativeApplicationId, UINT32 *applicationUserModelIdLength, // PWSTR applicationUserModelId ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("appmodel.h", MSDNShortId = "F48D19C2-6373-41FC-A99D-E3CCB68D6C6C")] public static extern Win32Error FormatApplicationUserModelId(string packageFamilyName, string packageRelativeApplicationId, ref uint applicationUserModelIdLength, StringBuilder applicationUserModelId); /// /// Gets the application user model ID for the specified process. /// /// /// /// A handle to the process. This handle must have the PROCESS_QUERY_LIMITED_INFORMATION access right. For more info, see /// Process Security and Access Rights. /// /// /// /// /// On input, the size of the applicationUserModelId buffer, in wide characters. On success, the size of the buffer used, including /// the null terminator. /// /// /// /// A pointer to a buffer that receives the application user model ID. /// /// /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// APPMODEL_ERROR_NO_APPLICATION /// The process has no application identity. /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by applicationUserModelIdLength. /// /// /// /// /// For info about string size limits, see Identity constants. /// Examples /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getapplicationusermodelid LONG // GetApplicationUserModelId( HANDLE hProcess, UINT32 *applicationUserModelIdLength, PWSTR applicationUserModelId ); [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [PInvokeData("appmodel.h", MSDNShortId = "FE4E0818-F548-494B-B3BD-FB51DC748451")] public static extern Win32Error GetApplicationUserModelId(HPROCESS hProcess, ref uint applicationUserModelIdLength, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder applicationUserModelId); /// /// Gets the application user model ID for the specified token. /// /// /// /// A token that contains the application identity. This handle must have the PROCESS_QUERY_LIMITED_INFORMATION access right. /// For more info, see Process Security and Access Rights. /// /// /// /// /// On input, the size of the applicationUserModelId buffer, in wide characters. On success, the size of the buffer used, including /// the null terminator. /// /// /// /// A pointer to a buffer that receives the application user model ID. /// /// /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// APPMODEL_ERROR_NO_APPLICATION /// The token has no application identity. /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by applicationUserModelIdLength. /// /// /// /// /// For info about string size limits, see Identity constants. /// Examples /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getapplicationusermodelidfromtoken LONG // GetApplicationUserModelIdFromToken( HANDLE token, UINT32 *applicationUserModelIdLength, PWSTR applicationUserModelId ); [DllImport(Lib.KernelBase, SetLastError = true, ExactSpelling = true)] [PInvokeData("appmodel.h", MSDNShortId = "80036518-927E-4CD0-B499-8EA472AB7E5A")] public static extern Win32Error GetApplicationUserModelIdFromToken(HTOKEN token, ref uint applicationUserModelIdLength, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder applicationUserModelId); /// /// Gets the application user model ID for the current process. /// /// /// /// On input, the size of the applicationUserModelId buffer, in wide characters. On success, the size of the buffer used, including /// the null terminator. /// /// /// /// A pointer to a buffer that receives the application user model ID. /// /// /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// APPMODEL_ERROR_NO_APPLICATION /// The process has no application identity. /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by applicationUserModelIdLength. /// /// /// /// /// For info about string size limits, see Identity constants. /// Examples /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getcurrentapplicationusermodelid LONG // GetCurrentApplicationUserModelId( UINT32 *applicationUserModelIdLength, PWSTR applicationUserModelId ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("appmodel.h", MSDNShortId = "562BB225-0922-4FE7-92C0-573A2CCE3195")] public static extern Win32Error GetCurrentApplicationUserModelId(ref uint applicationUserModelIdLength, StringBuilder applicationUserModelId); /// /// Gets the package family name for the calling process. /// /// /// Type: UINT32* /// /// On input, the size of the packageFamilyName buffer, in characters, including the null terminator. On output, the size of the /// package family name returned, in characters, including the null terminator. /// /// /// /// Type: PWSTR /// The package family name. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// APPMODEL_ERROR_NO_PACKAGE /// The process has no package identity. /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by packageFamilyNameLength. /// /// /// /// /// For info about string size limits, see Identity constants. /// Examples /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getcurrentpackagefamilyname LONG // GetCurrentPackageFamilyName( UINT32 *packageFamilyNameLength, PWSTR packageFamilyName ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("appmodel.h", MSDNShortId = "39DBFBDD-A1CC-45C3-A5DD-5ED9697F9AFE")] public static extern Win32Error GetCurrentPackageFamilyName(ref uint packageFamilyNameLength, StringBuilder packageFamilyName); /// /// Gets the package full name for the calling process. /// /// /// Type: UINT32* /// /// On input, the size of the packageFullName buffer, in characters. On output, the size of the package full name returned, in /// characters, including the null terminator. /// /// /// /// Type: PWSTR /// The package full name. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// APPMODEL_ERROR_NO_PACKAGE /// The process has no package identity. /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by packageFullNameLength. /// /// /// /// /// For info about string size limits, see Identity constants. /// Examples /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getcurrentpackagefullname LONG // GetCurrentPackageFullName( UINT32 *packageFullNameLength, PWSTR packageFullName ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("appmodel.h", MSDNShortId = "D5B00C53-1FBF-4245-92D1-FA39713A9EE7")] public static extern Win32Error GetCurrentPackageFullName(ref uint packageFullNameLength, StringBuilder packageFullName); /// /// Gets the package identifier (ID) for the calling process. /// /// /// Type: UINT32* /// On input, the size of buffer, in bytes. On output, the size of the structure returned, in bytes. /// /// /// Type: BYTE* /// The package ID, represented as a PACKAGE_ID structure. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// APPMODEL_ERROR_NO_PACKAGE /// The process has no package identity. /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by bufferLength. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getcurrentpackageid LONG GetCurrentPackageId( UINT32 // *bufferLength, BYTE *buffer ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("appmodel.h", MSDNShortId = "4CFC707A-2A5A-41FE-BB5F-6FECACC99271")] public static extern Win32Error GetCurrentPackageId(ref uint bufferLength, IntPtr buffer); /// /// Gets the package information for the calling process. /// /// /// Type: const UINT32 /// The package constants that specify how package information is retrieved. The PACKAGE_FILTER_* flags are supported. /// /// /// Type: UINT32* /// On input, the size of buffer, in bytes. On output, the size of the array of structures returned, in bytes. /// /// /// Type: BYTE* /// The package information, represented as an array of PACKAGE_INFO structures. /// /// /// Type: UINT32* /// The number of structures in the buffer. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// APPMODEL_ERROR_NO_PACKAGE /// The process has no package identity. /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by bufferLength. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getcurrentpackageinfo LONG GetCurrentPackageInfo( const // UINT32 flags, UINT32 *bufferLength, BYTE *buffer, UINT32 *count ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("appmodel.h", MSDNShortId = "A1887D61-0FAD-4BE8-850F-F104CC074798")] public static extern Win32Error GetCurrentPackageInfo(PACKAGE_FLAGS flags, ref uint bufferLength, IntPtr buffer, out uint count); /// /// Gets the package information for the calling process, with the option to specify the type of folder path to retrieve for the package. /// /// /// Type: const UINT32 /// The package constants that specify how package information is retrieved. The PACKAGE_FILTER_* flags are supported. /// /// /// Type: PackagePathType /// Indicates the type of folder path to retrieve for the package (the original install folder or the mutable folder). /// /// /// Type: UINT32* /// On input, the size of buffer, in bytes. On output, the size of the array of structures returned, in bytes. /// /// /// Type: BYTE* /// The package information, represented as an array of PACKAGE_INFO structures. /// /// /// Type: UINT32* /// The number of structures in the buffer. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error /// codes include the following. /// /// /// /// Return code /// Description /// /// /// APPMODEL_ERROR_NO_PACKAGE /// The process has no package identity. /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by bufferLength. /// /// /// /// /// The packagePathType parameter is useful for applications that use the windows.mutablePackageDirectories extension in their /// package manifest. This extension specifies a folder under the %ProgramFiles%\ModifiableWindowsApps path where the contents of /// the application's install folder are projected so that users can modify the installation files. This feature is currently /// available only for certain types of desktop PC games that are published by Microsoft and our partners, and it enables these /// types of games to support mods. /// // https://docs.microsoft.com/en-us/windows/win32/api/appmodel/nf-appmodel-getcurrentpackageinfo2 // LONG GetCurrentPackageInfo2( const UINT32 flags, PackagePathType packagePathType, UINT32 *bufferLength, BYTE *buffer, UINT32 *count ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("appmodel.h")] public static extern Win32Error GetCurrentPackageInfo2(PACKAGE_FLAGS flags, PackagePathType packagePathType, ref uint bufferLength, IntPtr buffer, out uint count); /// /// Gets the package path for the calling process. /// /// /// Type: UINT32* /// /// On input, the size of the path buffer, in characters. On output, the size of the package path returned, in characters, including /// the null terminator. /// /// /// /// Type: PWSTR /// The package path. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// APPMODEL_ERROR_NO_PACKAGE /// The process has no package identity. /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by pathLength. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getcurrentpackagepath LONG GetCurrentPackagePath( UINT32 // *pathLength, PWSTR path ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("appmodel.h", MSDNShortId = "46CE81DF-A9D5-492E-AB5E-4F043DC326E2")] public static extern Win32Error GetCurrentPackagePath(ref uint pathLength, StringBuilder path); /// /// Gets the package path for the calling process, with the option to specify the type of folder path to retrieve for the package. /// /// /// Type: PackagePathType /// Indicates the type of folder path to retrieve for the package (the original install folder or the mutable folder). /// /// /// Type: UINT32* /// /// On input, the size of the path buffer, in characters. On output, the size of the package path returned, in characters, including /// the null terminator. /// /// /// /// Type: PWSTR /// The package path. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error /// codes include the following. /// /// /// /// Return code /// Description /// /// /// APPMODEL_ERROR_NO_PACKAGE /// The process has no package identity. /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by pathLength. /// /// /// /// /// The packagePathType parameter is useful for applications that use the windows.mutablePackageDirectories extension in their /// package manifest. This extension specifies a folder under the %ProgramFiles%\ModifiableWindowsApps path where the contents of /// the application's install folder are projected so that users can modify the installation files. This feature is currently /// available only for certain types of desktop PC games that are published by Microsoft and our partners, and it enables these /// types of games to support mods. /// // https://docs.microsoft.com/en-us/windows/win32/api/appmodel/nf-appmodel-getcurrentpackagepath2 // LONG GetCurrentPackagePath2( PackagePathType packagePathType, UINT32 *pathLength, PWSTR path ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("appmodel.h")] public static extern Win32Error GetCurrentPackagePath2(PackagePathType packagePathType, ref uint pathLength, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder path); /// /// Gets the IDs of apps in the specified package. /// /// /// Type: PACKAGE_INFO_REFERENCE /// A reference to package information. /// /// /// Type: UINT32* /// A pointer to a variable that holds the size of buffer, in bytes. /// /// First you pass NULL to buffer to get the required size of buffer. You use this number to allocate memory space for buffer. /// Then you pass the address of this memory space to fill buffer. /// /// /// /// Type: BYTE* /// A pointer to memory space that receives the app IDs. /// /// /// Type: UINT32* /// A pointer to a variable that receives the number of app IDs in buffer. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by bufferLength. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getpackageapplicationids LONG GetPackageApplicationIds( // PACKAGE_INFO_REFERENCE packageInfoReference, UINT32 *bufferLength, BYTE *buffer, UINT32 *count ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("appmodel.h", MSDNShortId = "F08135F9-FF45-4309-84B5-77F4AFD7FC0C")] public static extern Win32Error GetPackageApplicationIds(PACKAGE_INFO_REFERENCE packageInfoReference, ref uint bufferLength, IntPtr buffer, out uint count); /// /// Gets the package family name for the specified process. /// /// /// Type: HANDLE /// /// A handle to the process that has the PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION access right. /// For more information, see Process Security and Access Rights. /// /// /// /// Type: UINT32* /// /// On input, the size of the packageFamilyName buffer, in characters. On output, the size of the package family name returned, in /// characters, including the null-terminator. /// /// /// /// Type: PWSTR /// The package family name. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// APPMODEL_ERROR_NO_PACKAGE /// The process has no package identity. /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by packageFamilyNameLength. /// /// /// /// /// For info about string size limits, see Identity constants. /// Examples /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getpackagefamilyname LONG GetPackageFamilyName( HANDLE // hProcess, UINT32 *packageFamilyNameLength, PWSTR packageFamilyName ); [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("appmodel.h", MSDNShortId = "AC239898-9924-4193-9072-7A7EEC2D03E9")] public static extern Win32Error GetPackageFamilyName(HPROCESS hProcess, ref uint packageFamilyNameLength, StringBuilder packageFamilyName); /// /// Gets the package family name for the specified token. /// /// /// Type: HANDLE /// A token that contains the package identity. /// /// /// Type: UINT32* /// /// On input, the size of the packageFamilyName buffer, in characters. On output, the size of the package family name returned, in /// characters, including the null-terminator. /// /// /// /// Type: PWSTR /// The package family name. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// APPMODEL_ERROR_NO_PACKAGE /// The token has no package identity. /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by packageFamilyNameLength. /// /// /// /// /// For info about string size limits, see Identity constants. /// Examples /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getpackagefamilynamefromtoken LONG // GetPackageFamilyNameFromToken( HANDLE token, UINT32 *packageFamilyNameLength, PWSTR packageFamilyName ); [DllImport(Lib.KernelBase, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("appmodel.h", MSDNShortId = "C4FAF5DE-DF1F-4AFA-813B-5D80C786031B")] public static extern Win32Error GetPackageFamilyNameFromToken(HTOKEN token, ref uint packageFamilyNameLength, StringBuilder packageFamilyName); /// /// Gets the package full name for the specified token. /// /// /// A token that contains the package identity. /// /// /// /// On input, the size of the packageFullName buffer, in characters. On output, the size of the package full name returned, in /// characters, including the null terminator. /// /// /// /// The package full name. /// /// /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// APPMODEL_ERROR_NO_PACKAGE /// The token has no package identity. /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by packageFullNameLength. /// /// /// /// /// For info about string size limits, see Identity constants. /// Examples /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getpackagefullnamefromtoken LONG // GetPackageFullNameFromToken( HANDLE token, UINT32 *packageFullNameLength, PWSTR packageFullName ); [DllImport(Lib.KernelBase, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("appmodel.h", MSDNShortId = "7B0D574E-A2F5-4D08-AEFB-9E040BBC729F")] public static extern Win32Error GetPackageFullNameFromToken(HTOKEN token, ref uint packageFullNameLength, StringBuilder packageFullName); /// /// Gets the package information for the specified package. /// /// /// Type: PACKAGE_INFO_REFERENCE /// A reference to package information. /// /// /// Type: const UINT32 /// The package constants that specify how package information is retrieved. /// /// /// Type: UINT32* /// On input, the size of buffer, in bytes. On output, the size of the package information returned, in bytes. /// /// /// Type: BYTE* /// The package information, represented as an array of PACKAGE_INFO structures. /// /// /// Type: UINT32* /// The number of packages in the buffer. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by bufferLength. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getpackageinfo LONG GetPackageInfo( // PACKAGE_INFO_REFERENCE packageInfoReference, const UINT32 flags, UINT32 *bufferLength, BYTE *buffer, UINT32 *count ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("appmodel.h", MSDNShortId = "28F45B3B-A61F-44D3-B606-6966AD5866FA")] public static extern Win32Error GetPackageInfo(PACKAGE_INFO_REFERENCE packageInfoReference, uint flags, ref uint bufferLength, IntPtr buffer, out uint count); /// /// Gets the package information for the specified package, with the option to specify the type of folder path to retrieve for the package. /// /// /// Type: PACKAGE_INFO_REFERENCE /// A reference to package information. /// /// /// Type: const UINT32 /// The package constants that specify how package information is retrieved. /// /// /// Type: PackagePathType /// Indicates the type of folder path to retrieve for the package (the original install folder or the mutable folder). /// /// /// Type: UINT32* /// On input, the size of buffer, in bytes. On output, the size of the package information returned, in bytes. /// /// /// Type: BYTE* /// The package information, represented as an array of PACKAGE_INFO structures. /// /// /// Type: UINT32* /// The number of packages in the buffer. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error /// codes include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by bufferLength. /// /// /// /// /// The packagePathType parameter is useful for applications that use the windows.mutablePackageDirectories extension in their /// package manifest. This extension specifies a folder under the %ProgramFiles%\ModifiableWindowsApps path where the contents of /// the application's install folder are projected so that users can modify the installation files. This feature is currently /// available only for certain types of desktop PC games that are published by Microsoft and our partners, and it enables these /// types of games to support mods. /// // https://docs.microsoft.com/en-us/windows/win32/api/appmodel/nf-appmodel-getpackageinfo2 // LONG GetPackageInfo2( PACKAGE_INFO_REFERENCE packageInfoReference, const UINT32 flags, PackagePathType packagePathType, UINT32 *bufferLength, BYTE *buffer, UINT32 *count ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("appmodel.h")] public static extern Win32Error GetPackageInfo2(PACKAGE_INFO_REFERENCE packageInfoReference, uint flags, PackagePathType packagePathType, ref uint bufferLength, IntPtr buffer, out uint count); /// /// Gets the path for the specified package. /// /// /// Type: const PACKAGE_ID* /// The package identifier. /// /// /// Type: const UINT32 /// Reserved, do not use. /// /// /// Type: UINT32* /// /// On input, the size of the path buffer, in characters. On output, the size of the package path returned, in characters, including /// the null-terminator. /// /// /// /// Type: PWSTR /// The package path. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer specified by path is not large enough to hold the data. The required size is specified by pathLength. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getpackagepath LONG GetPackagePath( const PACKAGE_ID // *packageId, const UINT32 reserved, UINT32 *pathLength, PWSTR path ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("appmodel.h", MSDNShortId = "BDA0DD87-A36D-486B-BF89-EA5CC105C742")] public static extern Win32Error GetPackagePath(ref PACKAGE_ID packageId, uint reserved, ref uint pathLength, StringBuilder path); /// /// Gets the path of the specified package. /// /// /// Type: PCWSTR /// The full name of the package. /// /// /// Type: UINT32* /// /// A pointer to a variable that holds the number of characters ( WCHAR s) in the package path string, which includes the null-terminator. /// /// /// First you pass NULL to path to get the number of characters. You use this number to allocate memory space for path. Then /// you pass the address of this memory space to fill path. /// /// /// /// Type: PWSTR /// A pointer to memory space that receives the package path string, which includes the null-terminator. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer specified by path is not large enough to hold the data. The required size is specified by pathLength. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getpackagepathbyfullname LONG GetPackagePathByFullName( // PCWSTR packageFullName, UINT32 *pathLength, PWSTR path ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("appmodel.h", MSDNShortId = "9C25708C-1464-4C59-9740-E9F105116385")] public static extern Win32Error GetPackagePathByFullName(string packageFullName, ref uint pathLength, StringBuilder path); /// Gets the path of the specified package, with the option to specify the type of folder path to retrieve for the package. /// /// Type: PCWSTR /// The full name of the package. /// /// /// Type: PackagePathType /// Indicates the type of folder path to retrieve for the package (the original install folder or the mutable folder). /// /// /// Type: UINT32* /// /// A pointer to a variable that holds the number of characters ( WCHAR s) in the package path string, which includes the null-terminator. /// /// /// First you pass NULL to path to get the number of characters. You use this number to allocate memory space for path. Then /// you pass the address of this memory space to fill path. /// /// /// /// Type: PWSTR /// A pointer to memory space that receives the package path string, which includes the null-terminator. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error /// codes include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer specified by path is not large enough to hold the data. The required size is specified by pathLength. /// /// /// /// /// The packagePathType parameter is useful for applications that use the windows.mutablePackageDirectories extension in their /// package manifest. This extension specifies a folder under the %ProgramFiles%\ModifiableWindowsApps path where the contents of /// the application's install folder are projected so that users can modify the installation files. This feature is currently /// available only for certain types of desktop PC games that are published by Microsoft and our partners, and it enables these /// types of games to support mods. /// // https://docs.microsoft.com/en-us/windows/win32/api/appmodel/nf-appmodel-getpackagepathbyfullname2 // LONG GetPackagePathByFullName2( PCWSTR packageFullName, PackagePathType packagePathType, UINT32 *pathLength, PWSTR path ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("appmodel.h")] public static extern Win32Error GetPackagePathByFullName2([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, PackagePathType packagePathType, ref uint pathLength, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder path); /// /// Gets the packages with the specified family name for the current user. /// /// /// Type: PCWSTR /// The package family name. /// /// /// Type: UINT32* /// A pointer to a variable that holds the number of package full names. /// /// First you pass NULL to packageFullNames to get the number of package full names. You use this number to allocate memory /// space for packageFullNames. Then you pass the address of this number to fill packageFullNames. /// /// /// /// Type: PWSTR* /// A pointer to the strings of package full names. /// /// /// Type: UINT32* /// A pointer to a variable that holds the number of characters in the string of package full names. /// /// First you pass NULL to buffer to get the number of characters. You use this number to allocate memory space for buffer. /// Then you pass the address of this number to fill buffer. /// /// /// /// Type: WCHAR* /// The string of characters for all of the package full names. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// One or more buffer is not large enough to hold the data. The required size is specified by either count or buffer. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getpackagesbypackagefamily LONG // GetPackagesByPackageFamily( PCWSTR packageFamilyName, UINT32 *count, PWSTR *packageFullNames, UINT32 *bufferLength, WCHAR *buffer ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("appmodel.h", MSDNShortId = "C2163203-D654-4491-9090-0CC43F42EC35")] public static extern Win32Error GetPackagesByPackageFamily(string packageFamilyName, ref uint count, [Out, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)] string[] packageFullNames, ref uint bufferLength, IntPtr buffer); /// /// Gets the origin of the specified package. /// /// /// Type: PCWSTR /// The full name of the package. /// /// /// Type: PackageOrigin* /// /// A pointer to a variable that receives a PackageOrigin-typed value that indicates the origin of the package specified by packageFullName. /// /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// The packageFullName parameter isn't valid. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getstagedpackageorigin LONG GetStagedPackageOrigin( // PCWSTR packageFullName, PackageOrigin *origin ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("appmodel.h", MSDNShortId = "7A1EE2CA-83CE-4E03-85A5-0061E29EB49B")] public static extern Win32Error GetStagedPackageOrigin(string packageFullName, out PackageOrigin origin); /// /// Gets the path of the specified staged package. /// /// /// Type: PCWSTR /// The full name of the staged package. /// /// /// Type: UINT32* /// /// A pointer to a variable that holds the number of characters ( WCHAR s) in the package path string, which includes the null-terminator. /// /// /// First you pass NULL to path to get the number of characters. You use this number to allocate memory space for path. Then /// you pass the address of this memory space to fill path. /// /// /// /// Type: PWSTR /// A pointer to memory space that receives the package path string, which includes the null-terminator. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer specified by path is not large enough to hold the data. The required size is specified by pathLength. /// /// /// /// /// /// This function succeeds if the package is staged, regardless of the user context or if the package is registered for the current user. /// /// Examples /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-getstagedpackagepathbyfullname LONG // GetStagedPackagePathByFullName( PCWSTR packageFullName, UINT32 *pathLength, PWSTR path ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("appmodel.h", MSDNShortId = "F0A37D77-6262-44B1-BEC5-083E41BDE139")] public static extern Win32Error GetStagedPackagePathByFullName([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, ref uint pathLength, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder path); /// /// Gets the path of the specified staged package, with the option to specify the type of folder path to retrieve for the package. /// /// /// Type: PCWSTR /// The full name of the staged package. /// /// /// Type: PackagePathType /// Indicates the type of folder path to retrieve for the package (the original install folder or the mutable folder). /// /// /// Type: UINT32* /// /// A pointer to a variable that holds the number of characters ( WCHAR s) in the package path string, which includes the null-terminator. /// /// /// First you pass NULL to path to get the number of characters. You use this number to allocate memory space for path. Then /// you pass the address of this memory space to fill path. /// /// /// /// Type: PWSTR /// A pointer to memory space that receives the package path string, which includes the null-terminator. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error /// codes include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer specified by path is not large enough to hold the data. The required size is specified by pathLength. /// /// /// /// /// The packagePathType parameter is useful for applications that use the windows.mutablePackageDirectories extension in their /// package manifest. This extension specifies a folder under the %ProgramFiles%\ModifiableWindowsApps path where the contents of /// the application's install folder are projected so that users can modify the installation files. This feature is currently /// available only for certain types of desktop PC games that are published by Microsoft and our partners, and it enables these /// types of games to support mods. /// // https://docs.microsoft.com/en-us/windows/win32/api/appmodel/nf-appmodel-getstagedpackagepathbyfullname2 // LONG GetStagedPackagePathByFullName2( PCWSTR packageFullName, PackagePathType packagePathType, UINT32 *pathLength, PWSTR path ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("appmodel.h")] public static extern Win32Error GetStagedPackagePathByFullName2([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, PackagePathType packagePathType, ref uint pathLength, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder path); /// /// Opens the package information of the specified package. /// /// /// Type: PCWSTR /// The full name of the package. /// /// /// Type: const UINT32 /// Reserved; must be 0. /// /// /// Type: PACKAGE_INFO_REFERENCE* /// A reference to package information. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_NOT_FOUND /// The package is not installed for the current user. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-openpackageinfobyfullname LONG // OpenPackageInfoByFullName( PCWSTR packageFullName, const UINT32 reserved, PACKAGE_INFO_REFERENCE *packageInfoReference ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("appmodel.h", MSDNShortId = "9ECFC757-1CB3-43A1-BA45-9AF72CAB240E")] public static extern Win32Error OpenPackageInfoByFullName([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, uint reserved, ref PACKAGE_INFO_REFERENCE packageInfoReference); /// /// Gets the package family name for the specified package full name. /// /// /// Type: PCWSTR /// The full name of a package. /// /// /// Type: UINT32* /// /// On input, the size of the packageFamilyName buffer, in characters. On output, the size of the package family name returned, in /// characters, including the null terminator. /// /// /// /// Type: PWSTR /// The package family name. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by packageFamilyNameLength. /// /// /// /// /// For info about string size limits, see Identity constants. /// Examples /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-packagefamilynamefromfullname LONG // PackageFamilyNameFromFullName( PCWSTR packageFullName, UINT32 *packageFamilyNameLength, PWSTR packageFamilyName ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("appmodel.h", MSDNShortId = "98E95CE5-E970-4A19-BAD3-994DAEC4BEA0")] public static extern Win32Error PackageFamilyNameFromFullName(string packageFullName, ref uint packageFamilyNameLength, StringBuilder packageFamilyName); /// /// Gets the package family name for the specified package identifier. /// /// /// Type: const PACKAGE_ID* /// The package identifier. /// /// /// Type: UINT32* /// /// On input, the size of the packageFamilyName buffer, in characters. On output, the size of the package family name returned, in /// characters, including the null terminator. /// /// /// /// Type: PWSTR /// The package family name. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by packageFamilyNameLength. /// /// /// /// /// For info about string size limits, see Identity constants. /// Examples /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-packagefamilynamefromid LONG PackageFamilyNameFromId( // const PACKAGE_ID *packageId, UINT32 *packageFamilyNameLength, PWSTR packageFamilyName ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("appmodel.h", MSDNShortId = "198DAB6B-21D2-4ACB-87DF-B3F4EFBEE323")] public static extern Win32Error PackageFamilyNameFromId(ref PACKAGE_ID packageId, ref uint packageFamilyNameLength, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder packageFamilyName); /// /// Gets the package full name for the specified package identifier (ID). /// /// /// Type: const PACKAGE_ID* /// The package ID. /// /// /// Type: UINT32* /// /// On input, the size of the packageFullName buffer, in characters. On output, the size of the package full name returned, in /// characters, including the null terminator. /// /// /// /// Type: PWSTR /// The package full name. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by packageFullNameLength. /// /// /// /// /// For info about string size limits, see Identity constants. /// Examples /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-packagefullnamefromid LONG PackageFullNameFromId( const // PACKAGE_ID *packageId, UINT32 *packageFullNameLength, PWSTR packageFullName ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("appmodel.h", MSDNShortId = "0024AF55-295E-49B1-90C2-9144D336529B")] public static extern Win32Error PackageFullNameFromId(ref PACKAGE_ID packageId, ref uint packageFullNameLength, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder packageFullName); /// /// Gets the package identifier (ID) for the specified package full name. /// /// /// Type: PCWSTR /// The full name of a package. /// /// /// Type: const UINT32 /// The package constants that specify how package information is retrieved. The PACKAGE_INFORMATION_* flags are supported. /// /// /// Type: UINT32* /// On input, the size of buffer, in bytes. On output, the size of the data returned, in bytes. /// /// /// Type: BYTE* /// The package ID, represented as a PACKAGE_ID structure. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer is not large enough to hold the data. The required size is specified by bufferLength. /// /// /// ERROR_NOT_FOUND /// The package is not installed for the user. /// /// /// /// /// If flags specifies PACKAGE_INFORMATION_BASIC, the following fields are retrieved: /// /// /// name /// /// /// processorArchitecture /// /// /// publisherId /// /// /// resourceId /// /// /// version /// /// /// If flags specifies PACKAGE_INFORMATION_FULL, the following fields are retrieved: /// /// /// name /// /// /// processorArchitecture /// /// /// publisher /// /// /// publisherId /// /// /// resourceId /// /// /// version /// /// /// /// A request for PACKAGE_INFORMATION_FULL succeeds only if the package corresponding to packageFullName is installed for and /// accessible to the current user. If the package full name is syntactically correct but does not correspond to a package that is /// installed for and accessible to the current user, the function returns ERROR_NOT_FOUND. /// /// For info about string size limits, see Identity constants. /// Examples /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-packageidfromfullname LONG PackageIdFromFullName( PCWSTR // packageFullName, const UINT32 flags, UINT32 *bufferLength, BYTE *buffer ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("appmodel.h", MSDNShortId = "EED832F8-E4F7-4A0F-93E2-451F78F67767")] public static extern Win32Error PackageIdFromFullName([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, PACKAGE_FLAGS flags, ref uint bufferLength, IntPtr buffer); /// /// Gets the package name and publisher identifier (ID) for the specified package family name. /// /// /// Type: PCWSTR /// The family name of a package. /// /// /// Type: UINT32* /// /// On input, the size of the packageName buffer, in characters. On output, the size of the package name returned, in characters, /// including the null-terminator. /// /// /// /// Type: PWSTR /// The package name. /// /// /// Type: UINT32* /// /// On input, the size of the packagePublishId buffer, in characters. On output, the size of the publisher ID returned, in /// characters, including the null-terminator. /// /// /// /// Type: PWSTR /// The package publisher ID. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// One of the buffers is not large enough to hold the data. The required sizes are specified by packageNameLength and packagePublisherIdLength. /// /// /// /// /// For info about string size limits, see Identity constants. /// Examples /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-packagenameandpublisheridfromfamilyname LONG // PackageNameAndPublisherIdFromFamilyName( PCWSTR packageFamilyName, UINT32 *packageNameLength, PWSTR packageName, UINT32 // *packagePublisherIdLength, PWSTR packagePublisherId ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("appmodel.h", MSDNShortId = "4AA5BD75-F865-40D6-9C10-E54C197D47C4")] public static extern Win32Error PackageNameAndPublisherIdFromFamilyName(string packageFamilyName, ref uint packageNameLength, StringBuilder packageName, ref uint packagePublisherIdLength, StringBuilder packagePublisherId); /// /// Deconstructs an application user model ID to its package family name and package relative application ID (PRAID). /// /// /// Type: PCWSTR /// The app user model ID. /// /// /// Type: UINT32* /// /// A pointer to a variable that holds the number of characters ( WCHAR s) in the package family name string, which includes /// the null-terminator. /// /// /// First you pass NULL to packageFamilyName to get the number of characters. You use this number to allocate memory space for /// packageFamilyName. Then you pass the address of this memory space to fill packageFamilyName. /// /// /// /// Type: PWSTR /// A pointer to memory space that receives the package family name string, which includes the null-terminator. /// /// /// Type: UINT32* /// /// A pointer to a variable that holds the number of characters ( WCHAR s) in the package-relative app ID string, which /// includes the null-terminator. /// /// /// First you pass NULL to packageRelativeApplicationId to get the number of characters. You use this number to allocate /// memory space for packageRelativeApplicationId. Then you pass the address of this memory space to fill packageRelativeApplicationId. /// /// /// /// Type: PWSTR /// A pointer to memory space that receives the package-relative app ID (PRAID) string, which includes the null-terminator. /// /// /// Type: LONG /// /// If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// The applicationUserModelId parameter isn't valid. /// /// /// ERROR_INSUFFICIENT_BUFFER /// /// The buffer specified by packageFamilyName or packageRelativeApplicationId is not large enough to hold the data; the required /// buffer size, in WCHARs, is stored in the variable pointed to by packageFamilyNameLength or packageRelativeApplicationIdLength. /// /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/nf-appmodel-parseapplicationusermodelid LONG // ParseApplicationUserModelId( PCWSTR applicationUserModelId, UINT32 *packageFamilyNameLength, PWSTR packageFamilyName, UINT32 // *packageRelativeApplicationIdLength, PWSTR packageRelativeApplicationId ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("appmodel.h", MSDNShortId = "03B29E82-611F-47D1-8CB6-047B9BEB4D9E")] public static extern Win32Error ParseApplicationUserModelId(string applicationUserModelId, ref uint packageFamilyNameLength, StringBuilder packageFamilyName, ref uint packageRelativeApplicationIdLength, StringBuilder packageRelativeApplicationId); /// /// Represents package identification information, such as name, version, and publisher. /// /// /// For info about string size limits, see Identity constants. /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/ns-appmodel-package_id typedef struct PACKAGE_ID { UINT32 reserved; // UINT32 processorArchitecture; PACKAGE_VERSION version; PWSTR name; PWSTR publisher; PWSTR resourceId; PWSTR publisherId; }; [PInvokeData("appmodel.h", MSDNShortId = "4B15281A-2227-47B7-A750-0A01DB8543FC")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct PACKAGE_ID { /// /// Type: UINT32 /// Reserved; do not use. /// public uint reserved; /// /// Type: UINT32 /// /// The processor architecture of the package. This member must be one of the values of the APPX_PACKAGE_ARCHITECTURE enumeration. /// /// public APPX_PACKAGE_ARCHITECTURE processorArchitecture; /// /// Type: PACKAGE_VERSION /// The version of the package. /// public PACKAGE_VERSION version; /// /// Type: PWSTR /// The name of the package. /// public string name; /// /// Type: PWSTR /// The publisher of the package. If there is no publisher for the package, this member is NULL. /// public string publisher; /// /// Type: PWSTR /// The resource identifier (ID) of the package. If there is no resource ID for the package, this member is NULL. /// public string resourceId; /// /// Type: PWSTR /// The publisher identifier (ID) of the package. If there is no publisher ID for the package, this member is NULL. /// public string publisherId; } /// Represents package identification information that includes the package identifier, full name, and install location. /// For info about string size limits, see Identity constants. // https://docs.microsoft.com/en-us/windows/win32/api/appmodel/ns-appmodel-package_info // typedef struct PACKAGE_INFO { UINT32 reserved; UINT32 flags; PWSTR path; PWSTR packageFullName; PWSTR packageFamilyName; PACKAGE_ID packageId; } PACKAGE_INFO; [PInvokeData("appmodel.h", MSDNShortId = "0DDE00D1-9C5F-4F2B-8110-A92B1FFA1B64")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct PACKAGE_INFO { /// Reserved; do not use. public uint reserved; /// Properties of the package. public uint flags; /// The location of the package. [MarshalAs(UnmanagedType.LPWStr)] public string path; /// The package full name/ [MarshalAs(UnmanagedType.LPWStr)] public string packageFullName; /// The package family name. [MarshalAs(UnmanagedType.LPWStr)] public string packageFamilyName; /// The package identifier (ID). public PACKAGE_ID packageId; } /// A reference to package information. [PInvokeData("appmodel.h")] [StructLayout(LayoutKind.Sequential)] public struct PACKAGE_INFO_REFERENCE { /// Reserved. public IntPtr reserved; } /// /// Represents the package version information. /// // https://docs.microsoft.com/en-us/windows/desktop/api/appmodel/ns-appmodel-package_version typedef struct PACKAGE_VERSION { union { // UINT64 Version; struct { USHORT Revision; USHORT Build; USHORT Minor; USHORT Major; } DUMMYSTRUCTNAME; } DUMMYUNIONNAME; }; [PInvokeData("appmodel.h", MSDNShortId = "8543DF84-A908-4DF5-AEE6-169FECB2AA97")] [StructLayout(LayoutKind.Explicit)] public struct PACKAGE_VERSION { /// /// Type: UINT64 /// The full version number of the package represented as a single integral value. /// [FieldOffset(0)] public ulong Version; /// Parts of the Version. [FieldOffset(0)] public DUMMYSTRUCTNAME Parts; /// Parts of the Version. public struct DUMMYSTRUCTNAME { /// /// Type: USHORT /// The revision version number of the package. /// public ushort Revision; /// /// Type: USHORT /// The build version number of the package. /// public ushort Build; /// /// Type: USHORT /// The minor version number of the package. /// public ushort Minor; /// /// Type: USHORT /// The major version number of the package. /// public ushort Major; } } } }