[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.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -6,6 +6,18 @@ namespace VMwareLauncher
|
||||
{
|
||||
public static void Shutdown(int exitCode)
|
||||
{
|
||||
switch (exitCode)
|
||||
{
|
||||
case 0:
|
||||
Startup.trayIcon.ShowShutdownSuccessMessage();
|
||||
break;
|
||||
case -1:
|
||||
Startup.trayIcon.WarnServiceShutdownFailure();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Startup.trayIcon.Destroy();
|
||||
Environment.Exit(exitCode);
|
||||
}
|
||||
|
||||
@@ -51,5 +51,5 @@ using System.Windows;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("2.0.9.6")]
|
||||
[assembly: AssemblyFileVersion("2.0.9.6")]
|
||||
[assembly: AssemblyVersion("2.0.9.7")]
|
||||
[assembly: AssemblyFileVersion("2.0.9.7")]
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ServiceProcess;
|
||||
using System.Linq;
|
||||
|
||||
namespace VMwareLauncher
|
||||
{
|
||||
@@ -38,5 +40,20 @@ namespace VMwareLauncher
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ namespace VMwareLauncher
|
||||
public partial class Startup : Window
|
||||
{
|
||||
static internal TrayIcon trayIcon = new TrayIcon();
|
||||
static internal ServiceControl serviceControl = new ServiceControl();
|
||||
internal StatusWindow statusWindow = new StatusWindow();
|
||||
internal CheckDependencies checkDependencies = new CheckDependencies();
|
||||
|
||||
@@ -24,9 +23,6 @@ namespace VMwareLauncher
|
||||
|
||||
checkDependencies.PerformCheck();
|
||||
|
||||
// Modify service status to manual.
|
||||
serviceControl.ForceServicesManual();
|
||||
|
||||
if (!vmLauncherControl.IsProcessRunning())
|
||||
{
|
||||
statusWindow.Show();
|
||||
|
||||
@@ -16,6 +16,9 @@ namespace VMwareLauncher
|
||||
BackgroundWorker runProcess = new BackgroundWorker();
|
||||
BackgroundWorker loadServices = new BackgroundWorker();
|
||||
BackgroundWorker stopServices = new BackgroundWorker();
|
||||
BackgroundWorker forceServicesManual = new BackgroundWorker();
|
||||
|
||||
ServiceControl serviceControl = new ServiceControl();
|
||||
|
||||
|
||||
public StatusWindow()
|
||||
@@ -29,11 +32,23 @@ namespace VMwareLauncher
|
||||
delayWindowHide.Tick += DelayWindowHide_Tick;
|
||||
delayWindowHide.Interval = new TimeSpan(0, 0, 2);
|
||||
|
||||
forceServicesManual.DoWork += ForceServicesManual_DoWork;
|
||||
runProcess.DoWork += RunProcess_DoWork;
|
||||
loadServices.DoWork += LoadServices_DoWork;
|
||||
stopServices.DoWork += StopServices_DoWork;
|
||||
|
||||
delayWindowHide.Start();
|
||||
forceServicesManual.RunWorkerAsync();
|
||||
}
|
||||
|
||||
private void ForceServicesManual_DoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
serviceControl.ForceServicesManual();
|
||||
}
|
||||
catch (Exception) { throw; }
|
||||
|
||||
loadServices.RunWorkerAsync();
|
||||
}
|
||||
|
||||
@@ -56,7 +71,18 @@ namespace VMwareLauncher
|
||||
sc.WaitForStatus(ServiceControllerStatus.Stopped);
|
||||
}
|
||||
}
|
||||
ApplicationControl.Shutdown(0);
|
||||
|
||||
// All 5 VMware Workstation services must be stopped to qualify
|
||||
// a successful shutdown.
|
||||
var stoppedVmServices = serviceControl.GetStoppedVmServices();
|
||||
if (stoppedVmServices.Count != 5)
|
||||
{
|
||||
ApplicationControl.Shutdown(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplicationControl.Shutdown(0);
|
||||
}
|
||||
}
|
||||
catch (Exception) { throw; }
|
||||
}
|
||||
|
||||
@@ -69,12 +69,24 @@ namespace VMwareLauncher
|
||||
}
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
public void WarnServiceShutdownFailure()
|
||||
{
|
||||
trayIcon.ShowBalloonTip(5000,
|
||||
"VMware Launcher",
|
||||
"VMware Launcher was unable to shutdown one or more Workstation services.",
|
||||
ToolTipIcon.Warning);
|
||||
}
|
||||
|
||||
public void ShowShutdownSuccessMessage()
|
||||
{
|
||||
trayIcon.ShowBalloonTip(3000,
|
||||
"VMware Launcher",
|
||||
"VMware Launcher has stopped all background Workstation services. Enjoy your day :-)",
|
||||
ToolTipIcon.None);
|
||||
ToolTipIcon.Info);
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
trayIcon.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user