对于那些可能因最近涉及Hyper-V的计算机更改而遇到此问题的人,您需要在使用VMWare或VirtualBox时将其禁用。他们不一起工作。Windows Sandbox和WSL 2需要打开Hyper-V虚拟机监控程序,该虚拟机当前会破坏VMWare。基本上,您将需要运行以下命令来在下次重启时启用/禁用Hyper-V服务。
要禁用Hyper-V并使VMWare工作,请在PowerShell中以Admin身份运行:
bcdedit /set hypervisorlaunchtype off
要暂时重新启用Hyper-V并中断VMWare,请在PowerShell中以Admin身份运行:
bcdedit /set hypervisorlaunchtype auto
之后,您需要重新启动。我已经编写了一个PowerShell脚本,它将为您切换此脚本并使用对话框进行确认。它甚至可以使用此技术自动提升为管理员,因此您只需右键单击并运行脚本即可快速更改Hyper-V模式。也可以轻松地对其进行修改以重新启动,但是我个人不希望这种情况发生。将其另存为hypervisor.ps1并确保已运行,Set-ExecutionPolicy RemoteSigned
以便可以运行PowerShell脚本。
# Get the ID and security principal of the current user account
$myWindowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent();
$myWindowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal($myWindowsID);
# Get the security principal for the administrator role
$adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator;
# Check to see if we are currently running as an administrator
if ($myWindowsPrincipal.IsInRole($adminRole))
{
# We are running as an administrator, so change the title and background colour to indicate this
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)";
$Host.UI.RawUI.BackgroundColor = "DarkBlue";
Clear-Host;
}
else {
# We are not running as an administrator, so relaunch as administrator
# Create a new process object that starts PowerShell
$newProcess = New-Object System.Diagnostics.ProcessStartInfo "PowerShell";
# Specify the current script path and name as a parameter with added scope and support for scripts with spaces in it's path
$newProcess.Arguments = "-windowstyle hidden & '" + $script:MyInvocation.MyCommand.Path + "'"
# Indicate that the process should be elevated
$newProcess.Verb = "runas";
# Start the new process
[System.Diagnostics.Process]::Start($newProcess);
# Exit from the current, unelevated, process
Exit;
}
Add-Type -AssemblyName System.Windows.Forms
$state = bcdedit /enum | Select-String -Pattern 'hypervisorlaunchtype\s*(\w+)\s*'
if ($state.matches.groups[1].ToString() -eq "Off"){
$UserResponse= [System.Windows.Forms.MessageBox]::Show("Enable Hyper-V?" , "Hypervisor" , 4)
if ($UserResponse -eq "YES" )
{
bcdedit /set hypervisorlaunchtype auto
[System.Windows.Forms.MessageBox]::Show("Enabled Hyper-V. Reboot to apply." , "Hypervisor")
}
else
{
[System.Windows.Forms.MessageBox]::Show("No change was made." , "Hypervisor")
exit
}
} else {
$UserResponse= [System.Windows.Forms.MessageBox]::Show("Disable Hyper-V?" , "Hypervisor" , 4)
if ($UserResponse -eq "YES" )
{
bcdedit /set hypervisorlaunchtype off
[System.Windows.Forms.MessageBox]::Show("Disabled Hyper-V. Reboot to apply." , "Hypervisor")
}
else
{
[System.Windows.Forms.MessageBox]::Show("No change was made." , "Hypervisor")
exit
}
}