From 8cbfdf1d57f1ab81b76d1d36ecb640fb39fb4baa Mon Sep 17 00:00:00 2001 From: Dima Iholkin <38999978+dima-iholkin@users.noreply.github.com> Date: Mon, 5 Oct 2020 00:32:04 +0300 Subject: [PATCH] Fix the installer. (#19) --- package.json | 2 +- src/installer/Installer.wxs | 100 ++++++++-- .../assets/install-scheduler-task.ps1 | 174 ++++++++++++++++-- 3 files changed, 249 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index fd7d014..46fe1a3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "switch-apps", - "version": "1.0.0", + "version": "1.0.1", "description": "Maybe a better way to switch apps (Alt+Tab) for Windows 10.", "main": "SwitchApps.ahk", "scripts": { diff --git a/src/installer/Installer.wxs b/src/installer/Installer.wxs index 984a11a..9dbe60d 100644 --- a/src/installer/Installer.wxs +++ b/src/installer/Installer.wxs @@ -3,9 +3,14 @@ + + + + + @@ -41,7 +46,7 @@ - + @@ -49,7 +54,7 @@ - + @@ -74,6 +79,9 @@ Key="Software\Classes\ms-officeapp\Shell\Open\Command" Type="raw" /> + + + @@ -102,6 +110,9 @@ Name="MsOfficeAdPopup_Backup" Type="raw" /> + + + @@ -135,6 +146,10 @@ + + THUMBNAIL_PREVIEW_SIZE_PREINSTALL + + + + + NOT THUMBNAIL_PREVIEW_SIZE_PREINSTALL + + + + + + + + + + + + + + + THUMBNAIL_PREVIEW_DELAY_PREINSTALL + + + + + NOT THUMBNAIL_PREVIEW_DELAY_PREINSTALL + + + + + + + + + + + + + MSOFFICE_AD_POPUP_PREINSTALL @@ -196,39 +251,39 @@ - + - + - + @@ -244,7 +299,9 @@ + + @@ -265,6 +322,10 @@ REMOVE="ALL" + + + REMOVE="ALL" + @@ -276,13 +337,24 @@ Directory="TARGETDIR" Impersonate="no" Return="check" - ExeCommand="powershell -Command "Start-Process powershell -Wait -WindowStyle Hidden -ArgumentList 'cd [INSTALLFOLDER]; . .\install-scheduler-task.ps1; Install -InstallDir "[INSTALLFOLDER]" -Name "$(var.Name)" -ModifySystemRegistry "$(var.ModifySystemRegistry)" ' "" /> + ExeCommand="powershell -executionpolicy bypass -Command " Write-Host "This is window 1" ; cd [INSTALLFOLDER]; . .\install-scheduler-task.ps1; Install -InstallDir [INSTALLFOLDER] -Name "$(var.Name)" -ModifySystemRegistry "$(var.ModifySystemRegistry)" ; "" /> + + + + + + + ExeCommand="powershell -executionpolicy bypass -Command " Write-Host "This is window 1" ; cd [INSTALLFOLDER]; . .\install-scheduler-task.ps1; Uninstall_Part2 -Name "$(var.Name)" -ModifySystemRegistry "$(var.ModifySystemRegistry)" -ThumbSizePreInstall "/[THUMBNAIL_PREVIEW_SIZE_PREUNINSTALL]" -ThumbDelayPreInstall "/[THUMBNAIL_PREVIEW_DELAY_PREUNINSTALL]" -MsOfficePopupPreInstall "[MSOFFICE_AD_POPUP_PREUNINSTALL]" ; "" /> \ No newline at end of file diff --git a/src/installer/assets/install-scheduler-task.ps1 b/src/installer/assets/install-scheduler-task.ps1 index d678437..2b774ab 100644 --- a/src/installer/assets/install-scheduler-task.ps1 +++ b/src/installer/assets/install-scheduler-task.ps1 @@ -9,6 +9,7 @@ function Install { [string] $ModifySystemRegistry ) Write-Output "Install started"; + # Start-Sleep -s 10; @@ -28,11 +29,25 @@ function Install { - $user = [System.Security.Principal.WindowsIdentity]::GetCurrent(); + # $user = [System.Security.Principal.WindowsIdentity]::GetCurrent(); - $P = New-ScheduledTaskPrincipal -UserId $user.User.Value -RunLevel Highest + $fullName = (Get-WMIObject -class Win32_ComputerSystem | select username).username; + $userName = $fullName.split("\")[1]; - $T = New-ScheduledTaskTrigger -AtLogon -User $user.Name + # $string = "/c wmic useraccount where name='" + $userName + "' get sid"; + # $obj = cmd.exe --% $string + # $obj = cmd.exe --% /c wmic useraccount where name='$userName' get sid + + $command = "cmd.exe --% /c wmic useraccount where name='" + $userName + "' get sid"; + $obj = iex $command; + $sid = $obj[2]; + + + # $P = New-ScheduledTaskPrincipal -UserId $user.User.Value -RunLevel Highest + $P = New-ScheduledTaskPrincipal -UserId $sid -RunLevel Highest + + # $T = New-ScheduledTaskTrigger -AtLogon -User $user.Name + $T = New-ScheduledTaskTrigger -AtLogon -User $fullName @@ -66,7 +81,7 @@ function Install { -function Uninstall { +function Uninstall_Part1 { [CmdletBinding()] param ( [Parameter()] @@ -81,6 +96,9 @@ function Uninstall { [string] $ModifySystemRegistry ) Write-Output "Uninstall started..."; + # Start-Sleep -s 10; + + $str = "ThumbSize: " + $ThumbSizePreInstall $str1 = "ThumbDelay: " + $ThumbDelayPreInstall @@ -113,15 +131,136 @@ function Uninstall { + # if ($ModifySystemRegistry -eq "true") { + + + + # $ThumbSizePostInstall = 800; + # $ThumbSizeCurrent = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Name "MinThumbSizePx").MinThumbSizePx + # if ($ThumbSizeCurrent -eq $ThumbSizePostInstall) { + # # if REG value now equals the PostInstall value, meaning nothing has changed it in between... + + # if ($ThumbSizePreInstall -eq "false") { + # Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Name "MinThumbSizePx"; + # } + # else { + # $thumbSizeInt = $ThumbSizePreInstall.Remove(0, 3) -as [int] + # Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Name "MinThumbSizePx" -Value $thumbSizeInt + # # ...then revert the value to the PreInstall one. + # } + # } + + + + # $ThumbDelayPostInstall = 0; + # $ThumbDelayCurrent = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name ExtendedUIHoverTime).ExtendedUIHoverTime + # if ($ThumbDelayCurrent -eq $ThumbDelayPostInstall) { + # # if REG value now equals the PostInstall value, meaning nothing has changed it in between... + + # if ($ThumbDelayPreInstall -eq "false") { + # Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "ExtendedUIHoverTime"; + # } + # else { + # $thumbDelayInt = $ThumbDelayPreInstall.Remove(0, 3) -as [int] + # Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "ExtendedUIHoverTime" -Value $thumbDelayInt + # # ...then revert the value to the PreInstall one. + # } + # } + + + + # $MsOfficePopupPostInstall = "rundll32"; + # $MsOfficePopupCurrent = (Get-ItemProperty -Path "HKCU:\Software\Classes\ms-officeapp\Shell\Open\Command").'(default)' + # if ($MsOfficePopupCurrent -eq $MsOfficePopupPostInstall) { + # # if REG value now equals the PostInstall value, meaning nothing has changed it in between... + + # if ($MsOfficePopupPreInstall -eq "false") { + # Remove-Item -Path "HKCU:\Software\Classes\ms-officeapp\Shell\Open\Command" + # } + # else { + # Set-ItemProperty -Path "HKCU:\Software\Classes\ms-officeapp\Shell\Open\Command" -Name '(default)' -Value $MsOfficePopupPreInstall + # } + # # ...then revert the value to the PreInstall one. + # } + + # Write-Output "Registry changes reverted." + # } + # else { + # Write-Output "ModifySystemRegistry = false" + # } +} + + + + + +function Uninstall_Part2 { + [CmdletBinding()] + param ( + [Parameter()] + [string] $ThumbSizePreInstall, + [Parameter()] + [string] $ThumbDelayPreInstall, + [Parameter()] + [string] $MsOfficePopupPreInstall, + [Parameter()] + [string] $Name, + [Parameter()] + [string] $ModifySystemRegistry + ) + Write-Output "Uninstall started..."; + # Start-Sleep -s 10; + + + + $str = "ThumbSize: " + $ThumbSizePreInstall + $str1 = "ThumbDelay: " + $ThumbDelayPreInstall + $str2 = "MsOfficePopup: " + $MsOfficePopupPreInstall + Write-Output $str + Write-Output $str1 + Write-Output $str2 + # Start-Sleep -Seconds 5 + + + + # Unregister-ScheduledTask -TaskPath "\$Name\" -TaskName "$Name autostart" -Confirm:$false + # # Remove the task scheduler task. + + + + # $scheduleObject = New-Object -ComObject Schedule.Service + # $scheduleObject.connect() + + # $rootFolder = $scheduleObject.GetFolder("\") + + # $appFolder = $rootFolder.GetFolder($Name) + + # if ($appFolder.GetTasks(0).Count -eq 0) { + # $rootFolder.DeleteFolder($Name, $null) + # } + # # Remove the task scheduler empty folder. + + # Write-Output "Scheduler task uninstalled." + + + if ($ModifySystemRegistry -eq "true") { + + + $ThumbSizePostInstall = 800; - $ThumbSizeCurrent = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Name MinThumbSizePx).MinThumbSizePx + $ThumbSizeCurrent = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Name "MinThumbSizePx").MinThumbSizePx if ($ThumbSizeCurrent -eq $ThumbSizePostInstall) { # if REG value now equals the PostInstall value, meaning nothing has changed it in between... - $thumbSizeInt = $ThumbSizePreInstall.Remove(0, 3) -as [int] - Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Name MinThumbSizePx -Value $thumbSizeInt - # ...then revert the value to the PreInstall one. + if ($ThumbSizePreInstall -eq "/false") { + Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Name "MinThumbSizePx"; + } + else { + $thumbSizeInt = $ThumbSizePreInstall.Remove(0, 3) -as [int] + Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Name "MinThumbSizePx" -Value $thumbSizeInt + # ...then revert the value to the PreInstall one. + } } @@ -131,11 +270,17 @@ function Uninstall { if ($ThumbDelayCurrent -eq $ThumbDelayPostInstall) { # if REG value now equals the PostInstall value, meaning nothing has changed it in between... - $thumbDelayInt = $ThumbDelayPreInstall.Remove(0, 3) -as [int] - Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name ExtendedUIHoverTime -Value $thumbDelayInt - # ...then revert the value to the PreInstall one. + if ($ThumbDelayPreInstall -eq "/false") { + Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "ExtendedUIHoverTime"; + } + else { + $thumbDelayInt = $ThumbDelayPreInstall.Remove(0, 3) -as [int] + Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "ExtendedUIHoverTime" -Value $thumbDelayInt + # ...then revert the value to the PreInstall one. + } } + $MsOfficePopupPostInstall = "rundll32"; $MsOfficePopupCurrent = (Get-ItemProperty -Path "HKCU:\Software\Classes\ms-officeapp\Shell\Open\Command").'(default)' @@ -143,7 +288,12 @@ function Uninstall { # if REG value now equals the PostInstall value, meaning nothing has changed it in between... if ($MsOfficePopupPreInstall -eq "false") { - Remove-Item -Path "HKCU:\Software\Classes\ms-officeapp\Shell\Open\Command" + $countRegValuesOnThisKey = (Get-Item -Path "HKCU:\Software\Classes\ms-officeapp\Shell\Open\Command").ValueCount; + if ($countRegValuesOnThisKey -eq 1) { + Remove-Item -Path "HKCU:\Software\Classes\ms-officeapp\Shell\Open\Command" + } else { + # there are other values on this key, so the key cannot be deleted. + } } else { Set-ItemProperty -Path "HKCU:\Software\Classes\ms-officeapp\Shell\Open\Command" -Name '(default)' -Value $MsOfficePopupPreInstall