From d99b4c1df17657f6bc177ee778a85d9226da21c1 Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL HE/HIM) (from Dev Box)" Date: Fri, 10 Apr 2026 21:50:00 -0700 Subject: [PATCH] Add error when using dism resources via Appx --- resources/dism_dsc/locales/en-us.toml | 1 + resources/dism_dsc/src/dism.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/resources/dism_dsc/locales/en-us.toml b/resources/dism_dsc/locales/en-us.toml index 5cd2f39ad..19a945a67 100644 --- a/resources/dism_dsc/locales/en-us.toml +++ b/resources/dism_dsc/locales/en-us.toml @@ -49,6 +49,7 @@ failedSerializeOutput = "Failed to serialize output: %{err}" failedLoadLibrary = "Failed to load dismapi.dll. Ensure DISM is available on this system." functionNotFound = "Failed to find function '%{name}' in dismapi.dll" initializeFailed = "DismInitialize failed: HRESULT %{hr}" +notSupportedAppx = "This resource currently is not supported when installed via Appx" openSessionFailed = "DismOpenSession failed: HRESULT %{hr}" getFeatureInfoFailed = "DismGetFeatureInfo failed for '%{name}': HRESULT %{hr}" enableFeatureFailed = "DismEnableFeature failed for '%{name}': HRESULT %{hr}" diff --git a/resources/dism_dsc/src/dism.rs b/resources/dism_dsc/src/dism.rs index 167b20597..aa693d8b0 100644 --- a/resources/dism_dsc/src/dism.rs +++ b/resources/dism_dsc/src/dism.rs @@ -14,6 +14,7 @@ const DISM_PACKAGE_NONE: i32 = 0; const ERROR_SUCCESS_REBOOT_REQUIRED: i32 = 3010; const DISMAPI_E_UNKNOWN_FEATURE: i32 = 0x800F080Cu32 as i32; const DISMAPI_E_CAPABILITY_NOT_APPLICABLE: i32 = 0x800F0825u32 as i32; +const REGDB_E_CLASSNOTREG: i32 = 0x80040154u32 as i32; const LOAD_LIBRARY_SEARCH_SYSTEM32: u32 = 0x0000_0800; #[link(name = "kernel32")] @@ -243,6 +244,9 @@ impl DismSessionHandle { unsafe { let hr = dism_initialize(DISM_LOG_ERRORS, std::ptr::null(), std::ptr::null()); + if hr == REGDB_E_CLASSNOTREG { + return Err(t!("dism.notSupportedAppx").to_string()); + } if hr < 0 { return Err(t!("dism.initializeFailed", hr = format!("0x{:08X}", hr as u32)).to_string()); } @@ -255,6 +259,10 @@ impl DismSessionHandle { std::ptr::null(), &mut session, ); + if hr == REGDB_E_CLASSNOTREG { + (api.shutdown)(); + return Err(t!("dism.notSupportedAppx").to_string()); + } if hr < 0 { (api.shutdown)(); return Err(t!("dism.openSessionFailed", hr = format!("0x{:08X}", hr as u32)).to_string());