Skip to content

Commit e8a3818

Browse files
authored
Merge pull request #1480 from SteveL-MSFT/backport-dism-error
Backport: Add error when using dism resources via Appx
2 parents 19635d4 + 89e8c98 commit e8a3818

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

resources/dism_dsc/locales/en-us.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ failedSerializeOutput = "Failed to serialize output: %{err}"
4949
failedLoadLibrary = "Failed to load dismapi.dll. Ensure DISM is available on this system."
5050
functionNotFound = "Failed to find function '%{name}' in dismapi.dll"
5151
initializeFailed = "DismInitialize failed: HRESULT %{hr}"
52+
notSupportedAppx = "This resource currently is not supported when installed via Appx"
5253
openSessionFailed = "DismOpenSession failed: HRESULT %{hr}"
5354
getFeatureInfoFailed = "DismGetFeatureInfo failed for '%{name}': HRESULT %{hr}"
5455
enableFeatureFailed = "DismEnableFeature failed for '%{name}': HRESULT %{hr}"

resources/dism_dsc/src/dism.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const DISM_PACKAGE_NONE: i32 = 0;
1414
const ERROR_SUCCESS_REBOOT_REQUIRED: i32 = 3010;
1515
const DISMAPI_E_UNKNOWN_FEATURE: i32 = 0x800F080Cu32 as i32;
1616
const DISMAPI_E_CAPABILITY_NOT_APPLICABLE: i32 = 0x800F0825u32 as i32;
17+
const REGDB_E_CLASSNOTREG: i32 = 0x80040154u32 as i32;
1718
const LOAD_LIBRARY_SEARCH_SYSTEM32: u32 = 0x0000_0800;
1819

1920
#[link(name = "kernel32")]
@@ -243,6 +244,9 @@ impl DismSessionHandle {
243244

244245
unsafe {
245246
let hr = dism_initialize(DISM_LOG_ERRORS, std::ptr::null(), std::ptr::null());
247+
if hr == REGDB_E_CLASSNOTREG {
248+
return Err(t!("dism.notSupportedAppx").to_string());
249+
}
246250
if hr < 0 {
247251
return Err(t!("dism.initializeFailed", hr = format!("0x{:08X}", hr as u32)).to_string());
248252
}
@@ -255,6 +259,10 @@ impl DismSessionHandle {
255259
std::ptr::null(),
256260
&mut session,
257261
);
262+
if hr == REGDB_E_CLASSNOTREG {
263+
(api.shutdown)();
264+
return Err(t!("dism.notSupportedAppx").to_string());
265+
}
258266
if hr < 0 {
259267
(api.shutdown)();
260268
return Err(t!("dism.openSessionFailed", hr = format!("0x{:08X}", hr as u32)).to_string());

0 commit comments

Comments
 (0)