Skip to content

Commit

Permalink
Switch back to HCS method and use reg method as backup
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Oct 10, 2021
1 parent 7096d40 commit 4df5daf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server/src/vmcompute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ fn get_wsl_vmid_by_hcs() -> std::io::Result<Option<Uuid>> {
Ok(None)
}

// This is unreliable, so only use this as a backup method.
pub fn get_wsl_vmid_by_reg() -> std::io::Result<Option<Uuid>> {
let list = winreg::RegKey::predef(winreg::enums::HKEY_LOCAL_MACHINE)
.open_subkey(r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\HostComputeService\VolatileStore\ComputeSystem")?;
Expand All @@ -104,5 +105,10 @@ pub fn get_wsl_vmid_by_reg() -> std::io::Result<Option<Uuid>> {
}

pub fn get_wsl_vmid() -> std::io::Result<Option<Uuid>> {
match get_wsl_vmid_by_hcs() {
Ok(v) => return Ok(v),
Err(err) if err.kind() == std::io::ErrorKind::PermissionDenied => (),
Err(err) => return Err(err),
}
get_wsl_vmid_by_reg()
}

0 comments on commit 4df5daf

Please sign in to comment.