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

Method create_key_helper

archive/ntreg/src/registry_key.rs:108–151  ·  view source on GitHub ↗
(&self, name: &str, must_create: bool)

Source from the content-addressed store, hash-verified

106 }
107
108 fn create_key_helper(&self, name: &str, must_create: bool) -> Result<RegistryKey, NtStatusError> {
109 let mut key_handle: HANDLE = INVALID_HANDLE_VALUE;
110 let mut disposition: u32 = 0;
111 let mut new_path = match convert_registry_path(&self.path) {
112 Ok(path) => path,
113 Err(err) => return Err(err),
114 };
115 new_path.push('\\');
116 new_path.push_str(name);
117 let key_path = name;
118 let obj = ObjectAttributes::new(self.handle, &key_path.to_string());
119 let status = unsafe {
120 ntregapi::NtCreateKey(
121 &mut key_handle,
122 KEY_CREATE_SUB_KEY,
123 &mut obj.as_struct(),
124 0,
125 null_mut(),
126 REG_OPTION_NON_VOLATILE,
127 &mut disposition
128 )
129 };
130
131 if !NT_SUCCESS(status) {
132 return Err(NtStatusError::new(status, "Failed to create key."));
133 }
134
135 if must_create && disposition == REG_OPENED_EXISTING_KEY {
136 return Err(NtStatusError::new(status, "Key already exists."));
137 }
138
139 Ok(
140 RegistryKey {
141 handle: key_handle,
142 path: new_path,
143 name: name.to_string(),
144 sub_key_count: 0,
145 max_key_name_len: 0,
146 value_count: 0,
147 max_value_name_len: 0,
148 max_data_len: 0,
149 }
150 )
151 }
152
153 /// Creates a new sub key.
154 ///

Callers 2

create_keyMethod · 0.80
create_or_get_keyMethod · 0.80

Calls 3

convert_registry_pathFunction · 0.85
as_structMethod · 0.80
newFunction · 0.50

Tested by

no test coverage detected