Files
Dunestorm f5b9c8f7a7 [VMware Launcher 2.0.9.7]
- Enhancement: #4 Verify Windows services have properly terminated upon shutdown.
- Moved instanciation of ServiceControl class from Startup.xaml.cs to StatusWindow.xaml.cs.
2021-04-13 12:04:14 +01:00

60 lines
1.7 KiB
C#

using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ServiceProcess;
using System.Linq;
namespace VMwareLauncher
{
public class ServiceControl
{
public static readonly List<string> VMwareServiceList = new List<string> //Array of services to close
{
"VMnetDHCP",
"VMUSBArbService",
"VMware NAT Service",
"VMwareHostd",
"VMAuthdService" };
public bool ForceServicesManual()
{
bool errors = false;
string winServices = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services";
try
{
foreach (var service in VMwareServiceList)
{
string currentService = winServices + "\\" + service;
if ((int)Registry.GetValue(currentService, "Start", null) != 3)
{
Registry.SetValue(currentService, "Start", 3);
}
}
}
catch (Exception)
{
errors = true;
throw;
}
return errors;
}
public List<string> GetStoppedVmServices()
{
var stoppedVmServices = new List<string>();
var services = ServiceController.GetServices();
foreach (var service in services)
{
if (service.Status == ServiceControllerStatus.Stopped &&
VMwareServiceList.Contains(service.ServiceName))
stoppedVmServices.Add(service.ServiceName);
}
return stoppedVmServices;
}
}
}