summaryrefslogtreecommitdiff
path: root/coin/provisioning/common/windows
diff options
context:
space:
mode:
authorJuha Karjalainen <juha.karjalainen@qt.io>2019-02-22 13:38:26 +0200
committerJuha Karjalainen <juha.karjalainen@qt.io>2019-03-15 09:13:16 +0000
commit48ab1d879bc5dc1f65ee6671e546f58ae1c67bee (patch)
treeb0480c38909bb0b7abb8697dc20ffde41da309c5 /coin/provisioning/common/windows
parentdeecc97dc248aaa2e5a51bcb00a351c2063b2420 (diff)
downloadqt5-48ab1d879bc5dc1f65ee6671e546f58ae1c67bee.tar.gz
Fix provisioning disable defragmentation for windows
If no scheduled task exist it would throw error causing provisioning to fail. Now catch when scheduling does not exist. Task-number: QTQAINFRA-2823 Change-Id: I3bf24df6116b6c978171950bf5bf954f5ddee533 Reviewed-by: Tony Sarajärvi <tony.sarajarvi@qt.io>
Diffstat (limited to 'coin/provisioning/common/windows')
-rw-r--r--coin/provisioning/common/windows/disable-defragment.ps142
1 files changed, 40 insertions, 2 deletions
diff --git a/coin/provisioning/common/windows/disable-defragment.ps1 b/coin/provisioning/common/windows/disable-defragment.ps1
index 876938f8..e76f0649 100644
--- a/coin/provisioning/common/windows/disable-defragment.ps1
+++ b/coin/provisioning/common/windows/disable-defragment.ps1
@@ -1,6 +1,6 @@
#############################################################################
##
-## Copyright (C) 2018 The Qt Company Ltd.
+## Copyright (C) 2019 The Qt Company Ltd.
## Contact: http://www.qt.io/licensing/
##
## This file is part of the provisioning scripts of the Qt Toolkit.
@@ -31,4 +31,42 @@
##
#############################################################################
-schtasks /Delete /TN "\Microsoft\Windows\Defrag\ScheduledDefrag" /F
+# Windows 7 does not have Get-ScheduledTask and Unregister-ScheduledTask
+# thus needing its own version.
+Write-Host "Disabling defragmentation"
+$version = Get-CimInstance Win32_OperatingSystem | Select-Object -ExpandProperty Caption
+if ($version -like '*Windows 7*'){
+ $pi = New-Object System.Diagnostics.ProcessStartInfo
+ $pi.FileName = "C:\Windows\System32\schtasks.exe"
+ $pi.RedirectStandardError = $true
+ $pi.UseShellExecute = $false
+ $pi.Arguments = "/Delete /TN `"\Microsoft\Windows\Defrag\ScheduledDefrag`" /F"
+ $prog = New-Object System.Diagnostics.Process
+ $prog.StartInfo = $pi
+ $prog.Start() | Out-Null
+ $err = $prog.StandardError.ReadToEnd()
+ $prog.WaitForExit()
+ if ($prog.ExitCode -eq 0){
+ Write-Host "Scheduled defragmentation removed"
+ } else {
+ if ($err -like '*cannot find the file*'){
+ Write-Host "No scheduled defragmentation task found"
+ exit 0
+ } else {
+ Write-Host "Error while deleting scheduled defragmentation task: $err"
+ }
+ }
+}
+else {
+ try {
+ $state = (Get-ScheduledTask -ErrorAction Stop -TaskName "ScheduledDefrag").State
+ Write-Host "Scheduled defragmentation task found in state: $state"
+ }
+ catch {
+ Write-Host "No scheduled defragmentation task found"
+ exit 0
+ }
+ Write-Host "Unregistering scheduled defragmentation task"
+ Unregister-ScheduledTask -ErrorAction Stop -Confirm:$false -TaskName ScheduledDefrag
+ Write-Host "Scheduled Defragmentation task was cancelled"
+}