From a1012f3402e9ddfc7e25389969dabfb772b8e8fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuli=20Sepp=C3=A4nen?= Date: Tue, 15 Nov 2016 12:39:49 +0200 Subject: [PATCH] Make service shutdown more robust MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Prevent stopping services that do not exist - Wait for the services to shut down before doing anything else Signed-off-by: Samuli Seppänen --- test-openvpn.ps1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test-openvpn.ps1 b/test-openvpn.ps1 index e1fe3ab..6c22c01 100644 --- a/test-openvpn.ps1 +++ b/test-openvpn.ps1 @@ -95,8 +95,12 @@ Function Stop-Gui { } Function Stop-Openvpnservice { - Stop-Service OpenVPNService - Stop-Service OpenVPNServiceLegacy + foreach ($service in 'OpenVPNService', 'OpenVPNServiceLegacy') { + if (Get-Service -Erroraction Ignore $service) { + Stop-Service $service + (Get-Service $service).WaitForStatus('Stopped') + } + } } # Stop all openvpn-related processes