diff --git a/.vs/VmwareLauncher/v16/.suo b/.vs/VmwareLauncher/v16/.suo index addd715..5d7eb50 100644 Binary files a/.vs/VmwareLauncher/v16/.suo and b/.vs/VmwareLauncher/v16/.suo differ diff --git a/VmwareLauncher/.vs/VMwareLauncher/v16/.suo b/VmwareLauncher/.vs/VMwareLauncher/v16/.suo new file mode 100644 index 0000000..d63fef0 Binary files /dev/null and b/VmwareLauncher/.vs/VMwareLauncher/v16/.suo differ diff --git a/VmwareLauncher/ApplicationControl.cs b/VmwareLauncher/ApplicationControl.cs index b0e83a4..d94a81c 100644 --- a/VmwareLauncher/ApplicationControl.cs +++ b/VmwareLauncher/ApplicationControl.cs @@ -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); } diff --git a/VmwareLauncher/Properties/AssemblyInfo.cs b/VmwareLauncher/Properties/AssemblyInfo.cs index 9f105e6..ece7249 100644 --- a/VmwareLauncher/Properties/AssemblyInfo.cs +++ b/VmwareLauncher/Properties/AssemblyInfo.cs @@ -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")] diff --git a/VmwareLauncher/ServiceControl.cs b/VmwareLauncher/ServiceControl.cs index 3808388..4eedeb8 100644 --- a/VmwareLauncher/ServiceControl.cs +++ b/VmwareLauncher/ServiceControl.cs @@ -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 GetStoppedVmServices() + { + var stoppedVmServices = new List(); + + var services = ServiceController.GetServices(); + foreach (var service in services) + { + if (service.Status == ServiceControllerStatus.Stopped && + VMwareServiceList.Contains(service.ServiceName)) + stoppedVmServices.Add(service.ServiceName); + } + + return stoppedVmServices; + } } } diff --git a/VmwareLauncher/Startup.xaml.cs b/VmwareLauncher/Startup.xaml.cs index fea2572..d441aee 100644 --- a/VmwareLauncher/Startup.xaml.cs +++ b/VmwareLauncher/Startup.xaml.cs @@ -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(); diff --git a/VmwareLauncher/StatusWindow.xaml.cs b/VmwareLauncher/StatusWindow.xaml.cs index 55e34f7..bc2c73d 100644 --- a/VmwareLauncher/StatusWindow.xaml.cs +++ b/VmwareLauncher/StatusWindow.xaml.cs @@ -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; } } diff --git a/VmwareLauncher/TrayIcon.cs b/VmwareLauncher/TrayIcon.cs index f2cd3a1..1ab96e7 100644 --- a/VmwareLauncher/TrayIcon.cs +++ b/VmwareLauncher/TrayIcon.cs @@ -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(); } } diff --git a/VmwareLauncher/bin/Release/VMwareLauncher.exe b/VmwareLauncher/bin/Release/VMwareLauncher.exe index bfbb812..99e3206 100644 Binary files a/VmwareLauncher/bin/Release/VMwareLauncher.exe and b/VmwareLauncher/bin/Release/VMwareLauncher.exe differ diff --git a/VmwareLauncher/bin/Release/VMwareLauncher.pdb b/VmwareLauncher/bin/Release/VMwareLauncher.pdb index 20b3fbc..a83e05d 100644 Binary files a/VmwareLauncher/bin/Release/VMwareLauncher.pdb and b/VmwareLauncher/bin/Release/VMwareLauncher.pdb differ