(&self, name: &str, must_create: bool)
| 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 | /// |
no test coverage detected