MCPcopy Create free account
hub / github.com/PowerShell/DSC / open

Method open

resources/dism_dsc/src/dism.rs:236–276  ·  view source on GitHub ↗

Opens a new DISM session for the online image. NOTE: `DismInitialize` and `DismShutdown` are per-process globals. Only one `DismSessionHandle` should exist at a time. Creating a second session while one is already open (or after one has been dropped) will call `DismInitialize` again, which returns `DISMAPI_E_DISMAPI_ALREADY_INITIALIZED`.

()

Source from the content-addressed store, hash-verified

234 /// dropped) will call `DismInitialize` again, which returns
235 /// `DISMAPI_E_DISMAPI_ALREADY_INITIALIZED`.
236 pub fn open() -> Result<Self, String> {
237 let api = DismApi::load()?;
238
239 // Load DismInitialize and DismOpenSession (only needed during open)
240 let dism_initialize: DismInitializeFn =
241 unsafe { load_fn(api.lib, b"DismInitialize\0")? };
242 let dism_open_session: DismOpenSessionFn =
243 unsafe { load_fn(api.lib, b"DismOpenSession\0")? };
244
245 unsafe {
246 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 }
250 if hr < 0 {
251 return Err(t!("dism.initializeFailed", hr = format!("0x{:08X}", hr as u32)).to_string());
252 }
253
254 let image_path = to_wide_null(DISM_ONLINE_IMAGE);
255 let mut session: u32 = 0;
256 let hr = dism_open_session(
257 image_path.as_ptr(),
258 std::ptr::null(),
259 std::ptr::null(),
260 &mut session,
261 );
262 if hr == REGDB_E_CLASSNOTREG {
263 (api.shutdown)();
264 return Err(t!("dism.notSupportedAppx").to_string());
265 }
266 if hr < 0 {
267 (api.shutdown)();
268 return Err(t!("dism.openSessionFailed", hr = format!("0x{:08X}", hr as u32)).to_string());
269 }
270
271 Ok(DismSessionHandle {
272 handle: session,
273 api,
274 })
275 }
276 }
277
278 pub fn get_feature_info(&self, feature_name: &str) -> Result<OptionalFeatureInfo, String> {
279 let wide_name = to_wide_null(feature_name);

Callers 4

setMethod · 0.45
getMethod · 0.45
read_sshd_configFunction · 0.45

Calls 2

load_fnFunction · 0.85
to_wide_nullFunction · 0.85

Tested by

no test coverage detected