Skip to content

Commit

Permalink
Merge pull request #54 from 0xf005ba11/missing-feature-handling
Browse files Browse the repository at this point in the history
better missing feature handling
  • Loading branch information
jxy-s authored May 4, 2023
2 parents 3907028 + 504c756 commit 2eb6a59
Showing 1 changed file with 52 additions and 7 deletions.
59 changes: 52 additions & 7 deletions VMPlex/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,70 @@ static private void CheckCapability()
// Before we show any other windows check that we can access the
// management service, if we can't then exit.
//
bool capable = false;
var state = GetVsmsState();
if (state == VsmsState.NoPermission)
{
UI.MessageBox.Show(
System.Windows.MessageBoxImage.Error,
"Virtual System Management",
"VMPlex is unable to interact with the Virtual Machine Management Service. " +
"Please run as administrator or add your user to the Hyper-V Administrators group.");
Environment.Exit(0xdead);
}
else if (state == VsmsState.NotInstalled)
{
var res = UI.MessageBox.Show(
System.Windows.MessageBoxImage.Error,
"Virtual System Management",
"VMPlex is unable to interact with the Virtual Machine Management Service. " +
"Please ensure that Windows Hyper-V is enabled on this machine. " +
"Open Windows Optional Features now?",
MessageBoxButton.YesNo);
if (res == MessageBoxResult.Yes)
{
LaunchOptionalFeaturesDialog();
}
Environment.Exit(0xdead);
}
}

private enum VsmsState
{
Ok,
NoPermission,
NotInstalled,
}

static private VsmsState GetVsmsState()
{
try
{
var vsms = new WmiScope(@"root\virtualization\v2")
.GetInstance<IMsvm_VirtualSystemManagementService>();
capable = (vsms != null);
return vsms != null ? VsmsState.Ok : VsmsState.NoPermission;
}
catch
{
return VsmsState.NotInstalled;
}
}

if (!capable)
static private void LaunchOptionalFeaturesDialog()
{
try
{
var p = new Process();
p.StartInfo.FileName = "OptionalFeatures.exe";
p.StartInfo.UseShellExecute = true;
p.Start();
}
catch (Exception ex)
{
UI.MessageBox.Show(
System.Windows.MessageBoxImage.Error,
"Virtual System Management",
"VMPlex is unable to interact with the Virtual Machine Management Service. " +
"Please run as administrator or add your user to the Hyper-V Administrators group.");
Environment.Exit(0xdead);
"VMPlex Workstation",
"Failed to launch OptionalFeatures.exe\n\n" +
ex.Message);
}
}

Expand Down

0 comments on commit 2eb6a59

Please sign in to comment.