From 5a065b1a02ad94e0d5e1a4612413cde29f1cd3ee Mon Sep 17 00:00:00 2001 From: Jeff Kluge Date: Wed, 4 Mar 2020 10:09:45 -0800 Subject: [PATCH] Update _DismAddProvisionedAppxPackage method (#88) Since this function was never public, it has changed in the latest release. It is now part of the public API so it shouldn't change again. Fixes #87 --- Directory.Build.props | 1 + dismapi.h | 916 +++++++++--------- global.json | 2 +- .../DismApi.AddProvisionedAppxPackage.cs | 94 +- 4 files changed, 556 insertions(+), 457 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index e4d4ebf..febd0e9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,7 @@ + true *log true true diff --git a/dismapi.h b/dismapi.h index c1ca5fc..2b9950d 100644 --- a/dismapi.h +++ b/dismapi.h @@ -20,111 +20,117 @@ extern "C" { #endif -////////////////////////////////////////////////////////////////////////////// -// -// Typedefs -// -////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////// + // + // Typedefs + // + ////////////////////////////////////////////////////////////////////////////// -typedef UINT DismSession; + typedef UINT DismSession; -////////////////////////////////////////////////////////////////////////////// -// -// Callbacks -// -////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////// + // + // Callbacks + // + ////////////////////////////////////////////////////////////////////////////// -typedef void (CALLBACK *DISM_PROGRESS_CALLBACK)(_In_ UINT Current, _In_ UINT Total, _In_opt_ PVOID UserData); + typedef void(CALLBACK* DISM_PROGRESS_CALLBACK)(_In_ UINT Current, _In_ UINT Total, _In_opt_ PVOID UserData); -////////////////////////////////////////////////////////////////////////////// -// -// Constants -// -////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////// + // + // Constants + // + ////////////////////////////////////////////////////////////////////////////// -#define DISM_ONLINE_IMAGE L"DISM_{53BFAE52-B167-4E2F-A258-0A37B57FF845}" -#define DISM_SESSION_DEFAULT 0 +#define DISM_ONLINE_IMAGE L"DISM_{53BFAE52-B167-4E2F-A258-0A37B57FF845}" +#define DISM_SESSION_DEFAULT 0 // Mount flags -#define DISM_MOUNT_READWRITE 0x00000000 -#define DISM_MOUNT_READONLY 0x00000001 -#define DISM_MOUNT_OPTIMIZE 0x00000002 -#define DISM_MOUNT_CHECK_INTEGRITY 0x00000004 +#define DISM_MOUNT_READWRITE 0x00000000 +#define DISM_MOUNT_READONLY 0x00000001 +#define DISM_MOUNT_OPTIMIZE 0x00000002 +#define DISM_MOUNT_CHECK_INTEGRITY 0x00000004 +#define DISM_MOUNT_SUPPORT_EA 0x00000008 // Unmount flags -#define DISM_COMMIT_IMAGE 0x00000000 -#define DISM_DISCARD_IMAGE 0x00000001 +#define DISM_COMMIT_IMAGE 0x00000000 +#define DISM_DISCARD_IMAGE 0x00000001 // Commit flags -#define DISM_COMMIT_GENERATE_INTEGRITY 0x00010000 -#define DISM_COMMIT_APPEND 0x00020000 +#define DISM_COMMIT_GENERATE_INTEGRITY 0x00010000 +#define DISM_COMMIT_APPEND 0x00020000 +#define DISM_COMMIT_SUPPORT_EA 0x00040000 // Commit flags may also be used with unmount. AND this with unmount flags and you will // get the commit-specific flags. -#define DISM_COMMIT_MASK 0xffff0000 +#define DISM_COMMIT_MASK 0xffff0000 -////////////////////////////////////////////////////////////////////////////// -// -// Enums -// -////////////////////////////////////////////////////////////////////////////// +// Reserved storage state flags +#define DISM_RESERVED_STORAGE_DISABLED 0x00000000 +#define DISM_RESERVED_STORAGE_ENABLED 0x00000001 -typedef enum _DismLogLevel -{ + ////////////////////////////////////////////////////////////////////////////// + // + // Enums + // + ////////////////////////////////////////////////////////////////////////////// + + typedef enum _DismLogLevel + { DismLogErrors = 0, DismLogErrorsWarnings, DismLogErrorsWarningsInfo -} DismLogLevel; + } DismLogLevel; -typedef enum _DismImageIdentifier -{ + typedef enum _DismImageIdentifier + { DismImageIndex = 0, DismImageName -} DismImageIdentifier; + } DismImageIdentifier; -typedef enum _DismMountMode -{ + typedef enum _DismMountMode + { DismReadWrite = 0, DismReadOnly -} DismMountMode; + } DismMountMode; -typedef enum _DismImageType -{ + typedef enum _DismImageType + { DismImageTypeUnsupported = -1, DismImageTypeWim = 0, DismImageTypeVhd = 1 -} DismImageType; + } DismImageType; -typedef enum _DismImageBootable -{ + typedef enum _DismImageBootable + { DismImageBootableYes = 0, DismImageBootableNo, DismImageBootableUnknown -} DismImageBootable; + } DismImageBootable; -typedef enum _DismMountStatus -{ + typedef enum _DismMountStatus + { DismMountStatusOk = 0, DismMountStatusNeedsRemount, DismMountStatusInvalid -} DismMountStatus; + } DismMountStatus; -typedef enum _DismImageHealthState -{ + typedef enum _DismImageHealthState + { DismImageHealthy = 0, DismImageRepairable, DismImageNonRepairable -} DismImageHealthState; + } DismImageHealthState; -typedef enum _DismPackageIdentifier -{ + typedef enum _DismPackageIdentifier + { DismPackageNone = 0, DismPackageName, DismPackagePath -} DismPackageIdentifier; + } DismPackageIdentifier; -typedef enum _DismPackageFeatureState -{ + typedef enum _DismPackageFeatureState + { DismStateNotPresent = 0, DismStateUninstallPending, DismStateStaged, @@ -134,10 +140,10 @@ typedef enum _DismPackageFeatureState DismStateInstallPending, DismStateSuperseded, DismStatePartiallyInstalled -} DismPackageFeatureState; + } DismPackageFeatureState; -typedef enum _DismReleaseType -{ + typedef enum _DismReleaseType + { DismReleaseTypeCriticalUpdate = 0, DismReleaseTypeDriver, DismReleaseTypeFeaturePack, @@ -153,65 +159,75 @@ typedef enum _DismReleaseType DismReleaseTypeLocalPack, DismReleaseTypeOther, DismReleaseTypeOnDemandPack -} DismReleaseType; + } DismReleaseType; -typedef enum _DismRestartType -{ + typedef enum _DismRestartType + { DismRestartNo = 0, DismRestartPossible, DismRestartRequired -} DismRestartType; + } DismRestartType; -typedef enum _DismDriverSignature -{ + typedef enum _DismDriverSignature + { DismDriverSignatureUnknown = 0, DismDriverSignatureUnsigned = 1, DismDriverSignatureSigned = 2 -} DismDriverSignature; + } DismDriverSignature; -typedef enum _DismFullyOfflineInstallableType -{ + typedef enum _DismFullyOfflineInstallableType + { DismFullyOfflineInstallable = 0, DismFullyOfflineNotInstallable, DismFullyOfflineInstallableUndetermined -} DismFullyOfflineInstallableType; - -////////////////////////////////////////////////////////////////////////////// -// -// Structs -// -////////////////////////////////////////////////////////////////////////////// + } DismFullyOfflineInstallableType; + + // Keep in-sync with StubPackageOption defined in onecore\base\ntsetup\opktools\dism\idl\AppxProviderInterfaces.idl. + // Need to redefine it here because the consumers of this header cannot import dismcore.tlb, where all DISM IDLs are + // built into. + typedef enum _DismStubPackageOption + { + DismStubPackageOptionNone = 0, + DismStubPackageOptionInstallFull = 1, + DismStubPackageOptionInstallStub = 2, + } DismStubPackageOption; + + ////////////////////////////////////////////////////////////////////////////// + // + // Structs + // + ////////////////////////////////////////////////////////////////////////////// #pragma pack(push, 1) -typedef struct _DismPackage -{ + typedef struct _DismPackage + { PCWSTR PackageName; DismPackageFeatureState PackageState; DismReleaseType ReleaseType; SYSTEMTIME InstallTime; -} DismPackage; + } DismPackage; -typedef struct _DismCustomProperty -{ + typedef struct _DismCustomProperty + { PCWSTR Name; PCWSTR Value; PCWSTR Path; -} DismCustomProperty; + } DismCustomProperty; -typedef struct _DismFeature -{ + typedef struct _DismFeature + { PCWSTR FeatureName; DismPackageFeatureState State; -} DismFeature; + } DismFeature; -typedef struct _DismCapability -{ + typedef struct _DismCapability + { PCWSTR Name; DismPackageFeatureState State; -} DismCapability; + } DismCapability; -typedef struct _DismPackageInfo -{ + typedef struct _DismPackageInfo + { PCWSTR PackageName; DismPackageFeatureState PackageState; DismReleaseType ReleaseType; @@ -234,21 +250,21 @@ typedef struct _DismPackageInfo UINT CustomPropertyCount; DismFeature* Feature; UINT FeatureCount; -} DismPackageInfo; + } DismPackageInfo; #ifdef __cplusplus -typedef struct _DismPackageInfoEx : public _DismPackageInfo -{ + typedef struct _DismPackageInfoEx : public _DismPackageInfo + { #else -typedef struct _DismPackageInfoEx -{ + typedef struct _DismPackageInfoEx + { DismPackageInfo; #endif PCWSTR CapabilityId; -} DismPackageInfoEx; + } DismPackageInfoEx; -typedef struct _DismFeatureInfo -{ + typedef struct _DismFeatureInfo + { PCWSTR FeatureName; DismPackageFeatureState FeatureState; PCWSTR DisplayName; @@ -256,36 +272,36 @@ typedef struct _DismFeatureInfo DismRestartType RestartRequired; DismCustomProperty* CustomProperty; UINT CustomPropertyCount; -} DismFeatureInfo; + } DismFeatureInfo; -typedef struct _DismCapabilityInfo -{ + typedef struct _DismCapabilityInfo + { PCWSTR Name; DismPackageFeatureState State; PCWSTR DisplayName; PCWSTR Description; DWORD DownloadSize; DWORD InstallSize; -} DismCapabilityInfo; + } DismCapabilityInfo; -typedef struct _DismString -{ + typedef struct _DismString + { PCWSTR Value; -} DismString; + } DismString; -typedef DismString DismLanguage; + typedef DismString DismLanguage; -typedef struct _DismWimCustomizedInfo -{ + typedef struct _DismWimCustomizedInfo + { UINT Size; UINT DirectoryCount; UINT FileCount; SYSTEMTIME CreatedTime; SYSTEMTIME ModifiedTime; -} DismWimCustomizedInfo; + } DismWimCustomizedInfo; -typedef struct _DismImageInfo -{ + typedef struct _DismImageInfo + { DismImageType ImageType; UINT ImageIndex; PCWSTR ImageName; @@ -309,19 +325,19 @@ typedef struct _DismImageInfo UINT LanguageCount; UINT DefaultLanguageIndex; VOID* CustomizedInfo; -} DismImageInfo; + } DismImageInfo; -typedef struct _DismMountedImageInfo -{ + typedef struct _DismMountedImageInfo + { PCWSTR MountPath; PCWSTR ImageFilePath; UINT ImageIndex; DismMountMode MountMode; DismMountStatus MountStatus; -} DismMountedImageInfo; + } DismMountedImageInfo; -typedef struct _DismDriverPackage -{ + typedef struct _DismDriverPackage + { PCWSTR PublishedName; PCWSTR OriginalFileName; BOOL InBox; @@ -337,10 +353,10 @@ typedef struct _DismDriverPackage UINT MinorVersion; UINT Build; UINT Revision; -} DismDriverPackage; + } DismDriverPackage; -typedef struct _DismDriver -{ + typedef struct _DismDriver + { PCWSTR ManufacturerName; PCWSTR HardwareDescription; PCWSTR HardwareId; @@ -348,311 +364,328 @@ typedef struct _DismDriver PCWSTR ServiceName; PCWSTR CompatibleIds; PCWSTR ExcludeIds; -} DismDriver; - -#pragma pack(pop) + } DismDriver; -////////////////////////////////////////////////////////////////////////////// -// -// Functions -// -////////////////////////////////////////////////////////////////////////////// - -HRESULT WINAPI -DismInitialize( - _In_ DismLogLevel LogLevel, - _In_opt_ PCWSTR LogFilePath, - _In_opt_ PCWSTR ScratchDirectory - ); - -HRESULT WINAPI -DismShutdown( - ); - -HRESULT WINAPI -DismMountImage( - _In_ PCWSTR ImageFilePath, - _In_ PCWSTR MountPath, - _In_ UINT ImageIndex, - _In_opt_ PCWSTR ImageName, - _In_ DismImageIdentifier ImageIdentifier, - _In_ DWORD Flags, - _In_opt_ HANDLE CancelEvent, - _In_opt_ DISM_PROGRESS_CALLBACK Progress, - _In_opt_ PVOID UserData - ); - -HRESULT WINAPI -DismUnmountImage( - _In_ PCWSTR MountPath, - _In_ DWORD Flags, - _In_opt_ HANDLE CancelEvent, - _In_opt_ DISM_PROGRESS_CALLBACK Progress, - _In_opt_ PVOID UserData - ); - -HRESULT WINAPI -DismOpenSession( - _In_ PCWSTR ImagePath, - _In_opt_ PCWSTR WindowsDirectory, - _In_opt_ PCWSTR SystemDrive, - _Out_ DismSession* Session - ); - -HRESULT WINAPI -DismCloseSession( - _In_ DismSession Session - ); - -HRESULT WINAPI -DismGetLastErrorMessage( - _Out_ DismString** ErrorMessage - ); - -HRESULT WINAPI -DismRemountImage( - _In_ PCWSTR MountPath - ); - -HRESULT WINAPI -DismCommitImage( - _In_ DismSession Session, - _In_ DWORD Flags, - _In_opt_ HANDLE CancelEvent, - _In_opt_ DISM_PROGRESS_CALLBACK Progress, - _In_opt_ PVOID UserData - ); - -HRESULT WINAPI -DismGetImageInfo( - _In_ PCWSTR ImageFilePath, - _Outptr_result_buffer_ (*Count) DismImageInfo** ImageInfo, - _Out_ UINT* Count - ); - -HRESULT WINAPI -DismGetMountedImageInfo( - _Outptr_result_buffer_(*Count) DismMountedImageInfo** MountedImageInfo, - _Out_ UINT* Count - ); - -HRESULT WINAPI -DismCleanupMountpoints( - ); - -HRESULT WINAPI -DismCheckImageHealth( - _In_ DismSession Session, - _In_ BOOL ScanImage, - _In_opt_ HANDLE CancelEvent, - _In_opt_ DISM_PROGRESS_CALLBACK Progress, - _In_opt_ PVOID UserData, - _Out_ DismImageHealthState* ImageHealth -); - -HRESULT WINAPI -DismRestoreImageHealth( - _In_ DismSession Session, - _In_reads_opt_(SourcePathCount) PCWSTR* SourcePaths, - _In_opt_ UINT SourcePathCount, - _In_ BOOL LimitAccess, - _In_opt_ HANDLE CancelEvent, - _In_opt_ DISM_PROGRESS_CALLBACK Progress, - _In_opt_ PVOID UserData -); - -HRESULT WINAPI -DismDelete( - _In_ VOID* DismStructure - ); - -HRESULT WINAPI -DismAddPackage( - _In_ DismSession Session, - _In_ PCWSTR PackagePath, - _In_ BOOL IgnoreCheck, - _In_ BOOL PreventPending, - _In_opt_ HANDLE CancelEvent, - _In_opt_ DISM_PROGRESS_CALLBACK Progress, - _In_opt_ PVOID UserData - ); - -HRESULT WINAPI -DismRemovePackage( - _In_ DismSession Session, - _In_ PCWSTR Identifier, - _In_ DismPackageIdentifier PackageIdentifier, - _In_opt_ HANDLE CancelEvent, - _In_opt_ DISM_PROGRESS_CALLBACK Progress, - _In_opt_ PVOID UserData - ); - -HRESULT WINAPI -DismEnableFeature( - _In_ DismSession Session, - _In_ PCWSTR FeatureName, - _In_opt_ PCWSTR Identifier, - _In_opt_ DismPackageIdentifier PackageIdentifier, - _In_ BOOL LimitAccess, - _In_reads_opt_(SourcePathCount) PCWSTR* SourcePaths, - _In_opt_ UINT SourcePathCount, - _In_ BOOL EnableAll, - _In_opt_ HANDLE CancelEvent, - _In_opt_ DISM_PROGRESS_CALLBACK Progress, - _In_opt_ PVOID UserData - ); - -HRESULT WINAPI -DismDisableFeature( - _In_ DismSession Session, - _In_ PCWSTR FeatureName, - _In_opt_ PCWSTR PackageName, - _In_ BOOL RemovePayload, - _In_opt_ HANDLE CancelEvent, - _In_opt_ DISM_PROGRESS_CALLBACK Progress, - _In_opt_ PVOID UserData - ); - -HRESULT WINAPI -DismGetPackages( - _In_ DismSession Session, - _Outptr_result_buffer_(*Count) DismPackage** Package, - _Out_ UINT* Count - ); - -HRESULT WINAPI -DismGetPackageInfo( - _In_ DismSession Session, - _In_ PCWSTR Identifier, - _In_ DismPackageIdentifier PackageIdentifier, - _Out_ DismPackageInfo** PackageInfo - ); - -HRESULT WINAPI -DismGetPackageInfoEx( - _In_ DismSession Session, - _In_ PCWSTR Identifier, - _In_ DismPackageIdentifier PackageIdentifier, - _Out_ DismPackageInfoEx** PackageInfoEx - ); - -HRESULT WINAPI -DismGetFeatures( - _In_ DismSession Session, - _In_opt_ PCWSTR Identifier, - _In_opt_ DismPackageIdentifier PackageIdentifier, - _Outptr_result_buffer_(*Count) DismFeature** Feature, - _Out_ UINT* Count - ); - -HRESULT WINAPI -DismGetFeatureInfo( - _In_ DismSession Session, - _In_ PCWSTR FeatureName, - _In_opt_ PCWSTR Identifier, - _In_opt_ DismPackageIdentifier PackageIdentifier, - _Out_ DismFeatureInfo** FeatureInfo - ); - -HRESULT WINAPI -DismGetFeatureParent( - _In_ DismSession Session, - _In_ PCWSTR FeatureName, - _In_opt_ PCWSTR Identifier, - _In_opt_ DismPackageIdentifier PackageIdentifier, - _Outptr_result_buffer_(*Count) DismFeature** Feature, - _Out_ UINT* Count - ); - -HRESULT WINAPI -DismApplyUnattend( - _In_ DismSession Session, - _In_ PCWSTR UnattendFile, - _In_ BOOL SingleSession - ); - -HRESULT WINAPI -DismAddDriver( - _In_ DismSession Session, - _In_ PCWSTR DriverPath, - _In_ BOOL ForceUnsigned - ); - -HRESULT WINAPI -DismRemoveDriver( - _In_ DismSession Session, - _In_ PCWSTR DriverPath - ); - -HRESULT WINAPI -DismGetDrivers( - _In_ DismSession Session, - _In_ BOOL AllDrivers, - _Outptr_result_buffer_(*Count) DismDriverPackage** DriverPackage, - _Out_ UINT* Count - ); - -HRESULT WINAPI -DismGetDriverInfo( - _In_ DismSession Session, - _In_ PCWSTR DriverPath, - _Outptr_result_buffer_(*Count) DismDriver** Driver, - _Out_ UINT* Count, - _Out_opt_ DismDriverPackage** DriverPackage - ); - - -HRESULT WINAPI -DismGetCapabilities( - _In_ DismSession Session, - _Outptr_result_buffer_(*Count) DismCapability** Capability, - _Out_ UINT* Count - ); - -HRESULT WINAPI -DismGetCapabilityInfo( - _In_ DismSession Session, - _In_ PCWSTR Name, - _Out_ DismCapabilityInfo** Info - ); - -HRESULT WINAPI -DismAddCapability( - _In_ DismSession Session, - _In_ PCWSTR Name, - _In_ BOOL LimitAccess, - _In_reads_opt_(SourcePathCount) PCWSTR* SourcePaths, - _In_opt_ UINT SourcePathCount, - _In_opt_ HANDLE CancelEvent, - _In_opt_ DISM_PROGRESS_CALLBACK Progress, - _In_opt_ PVOID UserData - ); - -HRESULT WINAPI -DismRemoveCapability( - _In_ DismSession Session, - _In_ PCWSTR Name, - _In_opt_ HANDLE CancelEvent, - _In_opt_ DISM_PROGRESS_CALLBACK Progress, - _In_opt_ PVOID UserData - ); + typedef struct _DismAppxPackage + { + PCWSTR PackageName; + PCWSTR DisplayName; + PCWSTR PublisherId; + UINT MajorVersion; + UINT MinorVersion; + UINT Build; + UINT RevisionNumber; + UINT Architecture; + PCWSTR ResourceId; + PCWSTR InstallLocation; + _Maybenull_ PCWSTR Region; -////////////////////////////////////////////////////////////////////////////// -// -// Success Codes -// -////////////////////////////////////////////////////////////////////////////// + } DismAppxPackage; -// For online scenario, computer needs to be restarted when the return value is ERROR_SUCCESS_REBOOT_REQUIRED (3010L). +#pragma pack(pop) -// -// MessageId: DISMAPI_S_RELOAD_IMAGE_SESSION_REQUIRED -// -// MessageText: -// -// The DISM session needs to be reloaded. -// -#define DISMAPI_S_RELOAD_IMAGE_SESSION_REQUIRED 0x00000001 + ////////////////////////////////////////////////////////////////////////////// + // + // Functions + // + ////////////////////////////////////////////////////////////////////////////// + + HRESULT WINAPI + DismInitialize( + _In_ DismLogLevel LogLevel, + _In_opt_ PCWSTR LogFilePath, + _In_opt_ PCWSTR ScratchDirectory); + + HRESULT WINAPI + DismShutdown(); + + HRESULT WINAPI + DismMountImage( + _In_ PCWSTR ImageFilePath, + _In_ PCWSTR MountPath, + _In_ UINT ImageIndex, + _In_opt_ PCWSTR ImageName, + _In_ DismImageIdentifier ImageIdentifier, + _In_ DWORD Flags, + _In_opt_ HANDLE CancelEvent, + _In_opt_ DISM_PROGRESS_CALLBACK Progress, + _In_opt_ PVOID UserData); + + HRESULT WINAPI + DismUnmountImage( + _In_ PCWSTR MountPath, + _In_ DWORD Flags, + _In_opt_ HANDLE CancelEvent, + _In_opt_ DISM_PROGRESS_CALLBACK Progress, + _In_opt_ PVOID UserData); + + HRESULT WINAPI + DismOpenSession( + _In_ PCWSTR ImagePath, + _In_opt_ PCWSTR WindowsDirectory, + _In_opt_ PCWSTR SystemDrive, + _Out_ DismSession* Session); + + HRESULT WINAPI + DismCloseSession( + _In_ DismSession Session); + + HRESULT WINAPI + DismGetLastErrorMessage( + _Out_ DismString** ErrorMessage); + + HRESULT WINAPI + DismRemountImage( + _In_ PCWSTR MountPath); + + HRESULT WINAPI + DismCommitImage( + _In_ DismSession Session, + _In_ DWORD Flags, + _In_opt_ HANDLE CancelEvent, + _In_opt_ DISM_PROGRESS_CALLBACK Progress, + _In_opt_ PVOID UserData); + + HRESULT WINAPI + DismGetImageInfo( + _In_ PCWSTR ImageFilePath, + _Outptr_result_buffer_(*Count) DismImageInfo** ImageInfo, + _Out_ UINT* Count); + + HRESULT WINAPI + DismGetMountedImageInfo( + _Outptr_result_buffer_(*Count) DismMountedImageInfo** MountedImageInfo, + _Out_ UINT* Count); + + HRESULT WINAPI + DismCleanupMountpoints(); + + HRESULT WINAPI + DismCheckImageHealth( + _In_ DismSession Session, + _In_ BOOL ScanImage, + _In_opt_ HANDLE CancelEvent, + _In_opt_ DISM_PROGRESS_CALLBACK Progress, + _In_opt_ PVOID UserData, + _Out_ DismImageHealthState* ImageHealth); + + HRESULT WINAPI + DismRestoreImageHealth( + _In_ DismSession Session, + _In_reads_opt_(SourcePathCount) PCWSTR* SourcePaths, + _In_opt_ UINT SourcePathCount, + _In_ BOOL LimitAccess, + _In_opt_ HANDLE CancelEvent, + _In_opt_ DISM_PROGRESS_CALLBACK Progress, + _In_opt_ PVOID UserData); + + HRESULT WINAPI + DismDelete( + _In_ VOID* DismStructure); + + HRESULT WINAPI + DismAddPackage( + _In_ DismSession Session, + _In_ PCWSTR PackagePath, + _In_ BOOL IgnoreCheck, + _In_ BOOL PreventPending, + _In_opt_ HANDLE CancelEvent, + _In_opt_ DISM_PROGRESS_CALLBACK Progress, + _In_opt_ PVOID UserData); + + HRESULT WINAPI + DismRemovePackage( + _In_ DismSession Session, + _In_ PCWSTR Identifier, + _In_ DismPackageIdentifier PackageIdentifier, + _In_opt_ HANDLE CancelEvent, + _In_opt_ DISM_PROGRESS_CALLBACK Progress, + _In_opt_ PVOID UserData); + + HRESULT WINAPI + DismEnableFeature( + _In_ DismSession Session, + _In_ PCWSTR FeatureName, + _In_opt_ PCWSTR Identifier, + _In_opt_ DismPackageIdentifier PackageIdentifier, + _In_ BOOL LimitAccess, + _In_reads_opt_(SourcePathCount) PCWSTR* SourcePaths, + _In_opt_ UINT SourcePathCount, + _In_ BOOL EnableAll, + _In_opt_ HANDLE CancelEvent, + _In_opt_ DISM_PROGRESS_CALLBACK Progress, + _In_opt_ PVOID UserData); + + HRESULT WINAPI + DismDisableFeature( + _In_ DismSession Session, + _In_ PCWSTR FeatureName, + _In_opt_ PCWSTR PackageName, + _In_ BOOL RemovePayload, + _In_opt_ HANDLE CancelEvent, + _In_opt_ DISM_PROGRESS_CALLBACK Progress, + _In_opt_ PVOID UserData); + + HRESULT WINAPI + DismGetPackages( + _In_ DismSession Session, + _Outptr_result_buffer_(*Count) DismPackage** Package, + _Out_ UINT* Count); + + HRESULT WINAPI + DismGetPackageInfo( + _In_ DismSession Session, + _In_ PCWSTR Identifier, + _In_ DismPackageIdentifier PackageIdentifier, + _Out_ DismPackageInfo** PackageInfo); + + HRESULT WINAPI + DismGetPackageInfoEx( + _In_ DismSession Session, + _In_ PCWSTR Identifier, + _In_ DismPackageIdentifier PackageIdentifier, + _Out_ DismPackageInfoEx** PackageInfoEx); + + HRESULT WINAPI + DismGetFeatures( + _In_ DismSession Session, + _In_opt_ PCWSTR Identifier, + _In_opt_ DismPackageIdentifier PackageIdentifier, + _Outptr_result_buffer_(*Count) DismFeature** Feature, + _Out_ UINT* Count); + + HRESULT WINAPI + DismGetFeatureInfo( + _In_ DismSession Session, + _In_ PCWSTR FeatureName, + _In_opt_ PCWSTR Identifier, + _In_opt_ DismPackageIdentifier PackageIdentifier, + _Out_ DismFeatureInfo** FeatureInfo); + + HRESULT WINAPI + DismGetFeatureParent( + _In_ DismSession Session, + _In_ PCWSTR FeatureName, + _In_opt_ PCWSTR Identifier, + _In_opt_ DismPackageIdentifier PackageIdentifier, + _Outptr_result_buffer_(*Count) DismFeature** Feature, + _Out_ UINT* Count); + + HRESULT WINAPI + DismApplyUnattend( + _In_ DismSession Session, + _In_ PCWSTR UnattendFile, + _In_ BOOL SingleSession); + + HRESULT WINAPI + DismAddDriver( + _In_ DismSession Session, + _In_ PCWSTR DriverPath, + _In_ BOOL ForceUnsigned); + + HRESULT WINAPI + DismRemoveDriver( + _In_ DismSession Session, + _In_ PCWSTR DriverPath); + + HRESULT WINAPI + DismGetDrivers( + _In_ DismSession Session, + _In_ BOOL AllDrivers, + _Outptr_result_buffer_(*Count) DismDriverPackage** DriverPackage, + _Out_ UINT* Count); + + HRESULT WINAPI + DismGetDriverInfo( + _In_ DismSession Session, + _In_ PCWSTR DriverPath, + _Outptr_result_buffer_(*Count) DismDriver** Driver, + _Out_ UINT* Count, + _Out_opt_ DismDriverPackage** DriverPackage); + + HRESULT WINAPI + DismGetCapabilities( + _In_ DismSession Session, + _Outptr_result_buffer_(*Count) DismCapability** Capability, + _Out_ UINT* Count); + + HRESULT WINAPI + DismGetCapabilityInfo( + _In_ DismSession Session, + _In_ PCWSTR Name, + _Out_ DismCapabilityInfo** Info); + + HRESULT WINAPI + DismAddCapability( + _In_ DismSession Session, + _In_ PCWSTR Name, + _In_ BOOL LimitAccess, + _In_reads_opt_(SourcePathCount) PCWSTR* SourcePaths, + _In_opt_ UINT SourcePathCount, + _In_opt_ HANDLE CancelEvent, + _In_opt_ DISM_PROGRESS_CALLBACK Progress, + _In_opt_ PVOID UserData); + + HRESULT WINAPI + DismRemoveCapability( + _In_ DismSession Session, + _In_ PCWSTR Name, + _In_opt_ HANDLE CancelEvent, + _In_opt_ DISM_PROGRESS_CALLBACK Progress, + _In_opt_ PVOID UserData); + + HRESULT WINAPI + DismGetReservedStorageState( + _In_ DismSession Session, + _Out_ PDWORD State); + + HRESULT WINAPI + DismSetReservedStorageState( + _In_ DismSession Session, + _In_ DWORD State); + + HRESULT WINAPI + _DismGetProvisionedAppxPackages( + DismSession Session, + _Outptr_result_buffer_(*Count) DismAppxPackage** Package, + _Out_ UINT* Count); + + HRESULT WINAPI + _DismAddProvisionedAppxPackage( + _In_ DismSession Session, + _In_ PCWSTR AppPath, + _In_reads_opt_(DependencyPackageCount) PCWSTR* DependencyPackages, + _In_ UINT DependencyPackageCount, + _In_reads_opt_(OptionalPackageCount) PCWSTR* OptionalPackages, + _In_ UINT OptionalPackageCount, + _In_reads_opt_(LicensePathCount) PCWSTR* LicensePaths, + _In_ UINT LicensePathCount, + _In_ BOOL SkipLicense, + _In_opt_ PCWSTR CustomDataPath, + _In_opt_ PCWSTR Region, + _In_ DismStubPackageOption stubPackageOption); + + HRESULT WINAPI + _DismRemoveProvisionedAppxPackage( + _In_ DismSession Session, + _In_ PCWSTR PackageName); + + ////////////////////////////////////////////////////////////////////////////// + // + // Success Codes + // + ////////////////////////////////////////////////////////////////////////////// + + // For online scenario, computer needs to be restarted when the return value is ERROR_SUCCESS_REBOOT_REQUIRED (3010L). + + // + // MessageId: DISMAPI_S_RELOAD_IMAGE_SESSION_REQUIRED + // + // MessageText: + // + // The DISM session needs to be reloaded. + // +#define DISMAPI_S_RELOAD_IMAGE_SESSION_REQUIRED 0x00000001 ////////////////////////////////////////////////////////////////////////////// // @@ -660,7 +693,6 @@ DismRemoveCapability( // ////////////////////////////////////////////////////////////////////////////// - // // MessageId: DISMAPI_E_DISMAPI_NOT_INITIALIZED // @@ -668,7 +700,7 @@ DismRemoveCapability( // // DISM API was not initialized for this process // -#define DISMAPI_E_DISMAPI_NOT_INITIALIZED 0xC0040001 +#define DISMAPI_E_DISMAPI_NOT_INITIALIZED 0xC0040001 // // MessageId: DISMAPI_E_SHUTDOWN_IN_PROGRESS @@ -677,7 +709,7 @@ DismRemoveCapability( // // A DismSession was being shutdown when another operation was called on it // -#define DISMAPI_E_SHUTDOWN_IN_PROGRESS 0xC0040002 +#define DISMAPI_E_SHUTDOWN_IN_PROGRESS 0xC0040002 // // MessageId: DISMAPI_E_OPEN_SESSION_HANDLES @@ -686,7 +718,7 @@ DismRemoveCapability( // // A DismShutdown was called while there were open DismSession handles // -#define DISMAPI_E_OPEN_SESSION_HANDLES 0xC0040003 +#define DISMAPI_E_OPEN_SESSION_HANDLES 0xC0040003 // // MessageId: DISMAPI_E_INVALID_DISM_SESSION @@ -695,7 +727,7 @@ DismRemoveCapability( // // An invalid DismSession handle was passed into a DISMAPI function // -#define DISMAPI_E_INVALID_DISM_SESSION 0xC0040004 +#define DISMAPI_E_INVALID_DISM_SESSION 0xC0040004 // // MessageId: DISMAPI_E_INVALID_IMAGE_INDEX @@ -704,7 +736,7 @@ DismRemoveCapability( // // An invalid image index was specified // -#define DISMAPI_E_INVALID_IMAGE_INDEX 0xC0040005 +#define DISMAPI_E_INVALID_IMAGE_INDEX 0xC0040005 // // MessageId: DISMAPI_E_INVALID_IMAGE_NAME @@ -713,7 +745,7 @@ DismRemoveCapability( // // An invalid image name was specified // -#define DISMAPI_E_INVALID_IMAGE_NAME 0xC0040006 +#define DISMAPI_E_INVALID_IMAGE_NAME 0xC0040006 // // MessageId: DISMAPI_E_UNABLE_TO_UNMOUNT_IMAGE_PATH @@ -722,7 +754,7 @@ DismRemoveCapability( // // An image that is not a mounted WIM or mounted VHD was attempted to be unmounted // -#define DISMAPI_E_UNABLE_TO_UNMOUNT_IMAGE_PATH 0xC0040007 +#define DISMAPI_E_UNABLE_TO_UNMOUNT_IMAGE_PATH 0xC0040007 // // MessageId: DISMAPI_E_LOGGING_DISABLED @@ -731,7 +763,7 @@ DismRemoveCapability( // // Failed to gain access to the log file user specified. Logging has been disabled.. // -#define DISMAPI_E_LOGGING_DISABLED 0xC0040009 +#define DISMAPI_E_LOGGING_DISABLED 0xC0040009 // // MessageId: DISMAPI_E_OPEN_HANDLES_UNABLE_TO_UNMOUNT_IMAGE_PATH @@ -740,7 +772,7 @@ DismRemoveCapability( // // A DismSession with open handles was attempted to be unmounted // -#define DISMAPI_E_OPEN_HANDLES_UNABLE_TO_UNMOUNT_IMAGE_PATH 0xC004000A +#define DISMAPI_E_OPEN_HANDLES_UNABLE_TO_UNMOUNT_IMAGE_PATH 0xC004000A // // MessageId: DISMAPI_E_OPEN_HANDLES_UNABLE_TO_MOUNT_IMAGE_PATH @@ -749,7 +781,7 @@ DismRemoveCapability( // // A DismSession with open handles was attempted to be mounted // -#define DISMAPI_E_OPEN_HANDLES_UNABLE_TO_MOUNT_IMAGE_PATH 0xC004000B +#define DISMAPI_E_OPEN_HANDLES_UNABLE_TO_MOUNT_IMAGE_PATH 0xC004000B // // MessageId: DISMAPI_E_OPEN_HANDLES_UNABLE_TO_REMOUNT_IMAGE_PATH @@ -758,7 +790,7 @@ DismRemoveCapability( // // A DismSession with open handles was attempted to be remounted // -#define DISMAPI_E_OPEN_HANDLES_UNABLE_TO_REMOUNT_IMAGE_PATH 0xC004000C +#define DISMAPI_E_OPEN_HANDLES_UNABLE_TO_REMOUNT_IMAGE_PATH 0xC004000C // // MessageId: DISMAPI_E_PARENT_FEATURE_DISABLED @@ -770,7 +802,7 @@ DismRemoveCapability( // 1 Call function DismGetFeatureParent to get all parent features and enable all of them. Or // 2 Set EnableAll to TRUE when calling function DismEnableFeature. // -#define DISMAPI_E_PARENT_FEATURE_DISABLED 0xC004000D +#define DISMAPI_E_PARENT_FEATURE_DISABLED 0xC004000D // // MessageId: DISMAPI_E_MUST_SPECIFY_ONLINE_IMAGE @@ -780,7 +812,7 @@ DismRemoveCapability( // The offline image specified is the running system. The macro DISM_ONLINE_IMAGE must be // used instead. // -#define DISMAPI_E_MUST_SPECIFY_ONLINE_IMAGE 0xC004000E +#define DISMAPI_E_MUST_SPECIFY_ONLINE_IMAGE 0xC004000E // // MessageId: DISMAPI_E_INVALID_PRODUCT_KEY @@ -790,7 +822,7 @@ DismRemoveCapability( // The specified product key could not be validated. Check that the specified // product key is valid and that it matches the target edition. // -#define DISMAPI_E_INVALID_PRODUCT_KEY 0xC004000F +#define DISMAPI_E_INVALID_PRODUCT_KEY 0xC004000F // // MessageId: DISMAPI_E_NEEDS_TO_REMOUNT_THE_IMAGE @@ -799,7 +831,7 @@ DismRemoveCapability( // // The image needs to be remounted before any servicing operation. // -#define DISMAPI_E_NEEDS_REMOUNT 0XC1510114 +#define DISMAPI_E_NEEDS_REMOUNT 0XC1510114 // // MessageId: DISMAPI_E_UNKNOWN_FEATURE @@ -808,7 +840,7 @@ DismRemoveCapability( // // The feature is not present in the package. // -#define DISMAPI_E_UNKNOWN_FEATURE 0x800f080c +#define DISMAPI_E_UNKNOWN_FEATURE 0x800f080c // // MessageId: DISMAPI_E_BUSY @@ -818,10 +850,10 @@ DismRemoveCapability( // The current package and feature servicing infrastructure is busy. Wait a // bit and try the operation again. // -#define DISMAPI_E_BUSY 0x800f0902 +#define DISMAPI_E_BUSY 0x800f0902 #ifdef __cplusplus -} + } #endif #endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_PKG_DISM) */ diff --git a/global.json b/global.json index aa3cc6e..6b02497 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "msbuild-sdks": { - "Microsoft.Build.CentralPackageVersions": "2.0.39" + "Microsoft.Build.CentralPackageVersions": "2.0.52" } } \ No newline at end of file diff --git a/src/Microsoft.Dism/DismApi.AddProvisionedAppxPackage.cs b/src/Microsoft.Dism/DismApi.AddProvisionedAppxPackage.cs index 827b16c..bc2b94a 100644 --- a/src/Microsoft.Dism/DismApi.AddProvisionedAppxPackage.cs +++ b/src/Microsoft.Dism/DismApi.AddProvisionedAppxPackage.cs @@ -2,7 +2,6 @@ // // Licensed under the MIT license. -using System; using System.Collections.Generic; using System.Runtime.InteropServices; @@ -21,11 +20,41 @@ public static partial class DismApi /// When the operation requires a reboot to complete. public static void AddProvisionedAppxPackage(DismSession session, string appPath, List dependencyPackages, string licensePath, string customDataPath) { - string[] dependencyPackagesArray = dependencyPackages?.ToArray() ?? new string[0]; - - bool skipLicense = String.IsNullOrEmpty(licensePath); + AddProvisionedAppxPackage( + session, + appPath, + dependencyPackages, + null, + string.IsNullOrEmpty(licensePath) ? null : new List { licensePath }, + customDataPath, + null); + } - int hresult = NativeMethods._DismAddProvisionedAppxPackage(session, appPath, dependencyPackagesArray, (uint)dependencyPackagesArray.Length, licensePath, skipLicense, customDataPath); + /// + /// Adds an app package (.appx) that will install for each new user to a Windows image. + /// + /// A valid DISM Session. + /// Specifies the location of the app package (.appx) to add to the Windows image. + /// Specifies the location of dependency packages. + /// Specifies the location of optional packages. + /// Specifies the locations of .xml files containing your application licenses. + /// Specifies the location of a custom data file. The custom data file will be renamed custom.data and saved in the app data store. + /// Specifies regions for the package. + /// When the operation requires a reboot to complete. + public static void AddProvisionedAppxPackage(DismSession session, string appPath, List dependencyPackages, List optionalPackages, List licensePaths, string customDataPath, string regions) + { + int hresult = NativeMethods._DismAddProvisionedAppxPackage( + session, + appPath, + dependencyPackages?.ToArray(), + (uint)(dependencyPackages?.Count ?? 0), + optionalPackages?.ToArray(), + (uint)(optionalPackages?.Count ?? 0), + licensePaths?.ToArray(), + (uint)(licensePaths?.Count ?? 0), + licensePaths == null || licensePaths.Count == 0, + customDataPath, + regions); DismUtilities.ThrowIfFail(hresult, session); } @@ -33,19 +62,56 @@ public static void AddProvisionedAppxPackage(DismSession session, string appPath internal static partial class NativeMethods { /// - /// Gets a provisioned appx package. + /// Adds a provisioned appx package. /// - /// A valid DISM Session. - /// The application path. - /// The dependent packages. - /// The dependent package count. - /// The license path. - /// Specifies whether the license should be skipped. - /// A custom path. + /// A valid DISM Session. + /// The application path. + /// The dependent packages. + /// The dependent package count. + /// The optional packages. + /// The optional package count. + /// The license paths. + /// The license path count. + /// Specifies whether the license should be skipped. + /// A custom path. + /// The regions. /// Returns S_OK on success. + /// + /// HRESULT WINAPI + /// _DismAddProvisionedAppxPackage( + /// _In_ DismSession Session, + /// _In_ PCWSTR AppPath, + /// _In_reads_opt_(DependencyPackageCount) PCWSTR* DependencyPackages, + /// _In_ UINT DependencyPackageCount, + /// _In_reads_opt_(OptionalPackageCount) PCWSTR* OptionalPackages, + /// _In_ UINT OptionalPackageCount, + /// _In_reads_opt_(LicensePathCount) PCWSTR* LicensePaths, + /// _In_ UINT LicensePathCount, + /// _In_ BOOL SkipLicense, + /// _In_opt_ PCWSTR CustomDataPath, + /// _In_opt_ PCWSTR Region, + /// _In_ DismStubPackageOption stubPackageOption); + /// [DllImport(DismDllName, CharSet = DismCharacterSet)] [return: MarshalAs(UnmanagedType.Error)] - public static extern int _DismAddProvisionedAppxPackage(DismSession session, [MarshalAs(UnmanagedType.LPWStr)] string appPath, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 3)] string[] dependencyPackages, UInt32 dependencyPackageCount, [MarshalAs(UnmanagedType.LPWStr)] string licensePath, bool skipLicense, [MarshalAs(UnmanagedType.LPWStr)] string customDataPath); + public static extern int _DismAddProvisionedAppxPackage( + DismSession Session, + [MarshalAs(UnmanagedType.LPWStr)] + string AppPath, + [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 3)] + string[] DependencyPackages, + uint DependencyPackageCount, + [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 5)] + string[] OptionalPackages, + uint OptionalPackageCount, + [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 7)] + string[] LicensePaths, + uint LicensePathCount, + bool SkipLicense, + [MarshalAs(UnmanagedType.LPWStr)] + string CustomDataPath, + [MarshalAs(UnmanagedType.LPWStr)] + string Regions); } } } \ No newline at end of file