Skip to content

Commit

Permalink
Move registry keys to future location
Browse files Browse the repository at this point in the history
  • Loading branch information
Romanitho committed Aug 31, 2024
1 parent bfa098b commit e16c12e
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 22 deletions.
8 changes: 4 additions & 4 deletions Sources/WAU/Gui.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function Start-Installations {
#Run Winget-Install script if box is checked
if ($AppToInstall) {
Start-PopUp "Installing applications..."
$WAUInstallPath = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\" -Name InstallLocation
$WAUInstallPath = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate\" -Name InstallLocation

#Try with admin rights.
try {
Expand Down Expand Up @@ -275,7 +275,7 @@ function Start-Uninstallations ($AppToUninstall) {
}

function Get-WAUInstallStatus {
$WAUVersion = Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\ -ErrorAction SilentlyContinue | Select-Object -ExpandProperty DisplayVersion -ErrorAction SilentlyContinue
$WAUVersion = Get-ItemProperty -Path HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate\ -ErrorAction SilentlyContinue | Select-Object -ExpandProperty DisplayVersion -ErrorAction SilentlyContinue
if ($WAUVersion -eq $WAUConfiguratorVersion) {
$WAULabelText = "WAU is currently installed (v$WAUVersion)."
$WAUStatus = "Green"
Expand Down Expand Up @@ -577,7 +577,7 @@ function Start-InstallGUI {
$UninstallWAUButton.add_click(
{
#Uninstall WAU from registry command
$Arguments = Get-ItemPropertyValue "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name "UninstallString"
$Arguments = Get-ItemPropertyValue "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate" -Name "UninstallString"
Start-Process "cmd.exe" -ArgumentList "/c $Arguments" -Wait -Verb RunAs
$WAUInstallStatus = Get-WAUInstallStatus
$WAUStatusLabel.Text = $WAUInstallStatus[0]
Expand Down Expand Up @@ -699,7 +699,7 @@ function Start-InstallGUI {
$LogButton.add_click(
{
try {
$LogPath = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\" -Name InstallLocatifon
$LogPath = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate\" -Name InstallLocatifon
Start-Process "$LogPath\Logs"
}
catch {
Expand Down
6 changes: 3 additions & 3 deletions Sources/WAU/Winget-AutoUpdate-Install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ function Uninstall-WingetAutoUpdate {
Write-ToLog "Uninstalling WAU started!" "Yellow"

#Get registry install location
$InstallLocation = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\" -Name InstallLocation -ErrorAction SilentlyContinue
$InstallLocation = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate\" -Name InstallLocation -ErrorAction SilentlyContinue

#Check if installed location exists and delete
if ($InstallLocation) {
Expand All @@ -383,7 +383,7 @@ function Uninstall-WingetAutoUpdate {
Get-ChildItem -Path $InstallLocation -Exclude *.txt, mods, logs | Remove-Item -Recurse -Force
}
& reg delete "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /f | Out-Null
& reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" /f | Out-Null
& reg delete "HKLM\SOFTWARE\Romanitho\Winget-AutoUpdate" /f | Out-Null

if ((Test-Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)")) {
Remove-Item -Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)" -Recurse -Force | Out-Null
Expand Down Expand Up @@ -488,7 +488,7 @@ Write-Host "`t https://github.com/Romanitho/Winget-AutoUpdate`n" -Foreground
Write-Host "`t________________________________________________________`n"

#Define WAU registry key
$Script:regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
$Script:regPath = "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate"

if (!$Uninstall) {
Write-ToLog " INSTALLING WAU" -LogColor "Cyan" -IsHeader
Expand Down
4 changes: 2 additions & 2 deletions Sources/WAU/Winget-AutoUpdate/WAU-Policies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Daily update settings from policies
$ActivateGPOManagement = Get-ItemPropertyValue "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -Name "WAU_ActivateGPOManagement" -ErrorAction SilentlyContinue
if ($ActivateGPOManagement -eq 1) {
#Add (or update) tag to activate WAU-Policies Management
New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name WAU_RunGPOManagement -Value 1 -Force | Out-Null
New-ItemProperty "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate" -Name WAU_RunGPOManagement -Value 1 -Force | Out-Null
}

#Get WAU settings
Expand All @@ -32,7 +32,7 @@ if ($WAUConfig.WAU_RunGPOManagement -eq 1) {
Add-Content -Path $GPOLogFile -Value "GPO Management Enabled. Policies updated."
}
else {
New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name WAU_RunGPOManagement -Value 0 -Force | Out-Null
New-ItemProperty "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate" -Name WAU_RunGPOManagement -Value 0 -Force | Out-Null
$WAUConfig.WAU_RunGPOManagement = 0
Add-Content -Path $GPOLogFile -Value "GPO Management Disabled. Policies removed."
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/WAU/Winget-AutoUpdate/WAU-Uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Write-Host "`t________________________________________________________`n`n"
try {
Write-host "Uninstalling WAU..." -ForegroundColor Yellow
#Get registry install location
$InstallLocation = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\" -Name InstallLocation
$InstallLocation = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate\" -Name InstallLocation

#Check if installed location exists and delete
if (Test-Path ($InstallLocation)) {
Expand All @@ -52,7 +52,7 @@ try {
Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
Get-ScheduledTask -TaskName "Winget-AutoUpdate-Policies" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
& reg delete "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /f | Out-Null
& reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" /f | Out-Null
& reg delete "HKLM\SOFTWARE\Romanitho\Winget-AutoUpdate" /f | Out-Null
if (Test-Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate") {
& reg delete "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" /f | Out-Null
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/WAU/Winget-AutoUpdate/Winget-Install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ $CurrentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Pri
$Script:IsElevated = $CurrentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

#Get WAU Installed location
$WAURegKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\"
$WAURegKey = "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate\"
$Script:WAUInstallLocation = Get-ItemProperty $WAURegKey -ErrorAction SilentlyContinue | Select-Object -ExpandProperty InstallLocation

#LogPath initialisation
Expand Down
2 changes: 1 addition & 1 deletion Sources/WAU/Winget-AutoUpdate/Winget-Notify.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Send Notify Script

#get xml notif config
$WAUinstalledPath = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\" -Name InstallLocation
$WAUinstalledPath = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate\" -Name InstallLocation
[xml]$NotifConf = Get-Content "$WAUinstalledPath\config\notif.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
if (!($NotifConf)) {
break
Expand Down
2 changes: 1 addition & 1 deletion Sources/WAU/Winget-AutoUpdate/functions/Get-WAUConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Function Get-WAUConfig {

#Get WAU Configurations from install config
$WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -ErrorAction SilentlyContinue
$WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue

#Check if GPO Management is enabled
$ActivateGPOManagement = Get-ItemPropertyValue "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -Name "WAU_ActivateGPOManagement" -ErrorAction SilentlyContinue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function Invoke-PostUpdateActions {
$null = Update-WinGet

#Create WAU Regkey if not present
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
$regPath = "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate"
if (!(test-path $regPath)) {
New-Item $regPath -Force
New-ItemProperty $regPath -Name DisplayName -Value "Winget-AutoUpdate (WAU)" -Force
Expand Down Expand Up @@ -113,8 +113,8 @@ function Invoke-PostUpdateActions {
}

#Remove old registry key
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name "VersionMajor" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name "VersionMinor" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate" -Name "VersionMajor" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate" -Name "VersionMinor" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -Name "VersionMajor" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -Name "VersionMinor" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -Name "DisplayVersion" -ErrorAction SilentlyContinue
Expand Down Expand Up @@ -143,11 +143,24 @@ function Invoke-PostUpdateActions {
Write-ToLog "-> Policies task created."
}

#Migrate registry to new location (MSI Prerequisites)
$sourcePath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
$destinationPath = "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate"
if (-not (Test-Path (Split-Path $destinationPath))) {
New-Item -Path (Split-Path $destinationPath) -ItemType Directory
}
try {
Move-Item -Path $sourcePath -Destination $destinationPath -Force
Write-ToLog "-> Migrated registry from $sourcePath to $destinationPath."
}
catch {
Write-ToLog "-> Failed tro migrate registry to new location"
}

### End of post update actions ###

#Reset WAU_UpdatePostActions Value
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name "WAU_PostUpdateActions" -Value 0 -Force | Out-Null
New-ItemProperty -Path "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate" -Name "WAU_PostUpdateActions" -Value 0 -Force | Out-Null

#Get updated WAU Config
$Script:WAUConfig = Get-WAUConfig
Expand Down
4 changes: 2 additions & 2 deletions Sources/WAU/Winget-AutoUpdate/functions/Update-WAU.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ function Update-WAU {
Remove-Item -Path $location -Recurse -Force -ErrorAction SilentlyContinue

#Set new version to registry
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name "DisplayVersion" -Value $WAUAvailableVersion -Force | Out-Null
New-ItemProperty -Path "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate" -Name "DisplayVersion" -Value $WAUAvailableVersion -Force | Out-Null

#Set Post Update actions to 1
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name "WAU_PostUpdateActions" -Value 1 -Force | Out-Null
New-ItemProperty -Path "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate" -Name "WAU_PostUpdateActions" -Value 1 -Force | Out-Null

#Send success Notif
Write-ToLog "WAU Update completed." "Green"
Expand Down
4 changes: 2 additions & 2 deletions Sources/WAU/Winget-AutoUpdate/mods/_AppID-template.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $AllVersions = $False
$Lnk = @("")

#Registry _value_ (DWord/String) to add in existing registry Key (Key created if not existing). Example:
#$AddKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
#$AddKey = "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate"
#$AddValue = "WAU_BypassListForUsers"
#$AddTypeData = "1"
#$AddType = "DWord"
Expand All @@ -46,7 +46,7 @@ $AddType = ""

#Registry _value_ to delete in existing registry Key.
#Value can be omitted for deleting entire Key!. Example:
#$DelKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
#$DelKey = "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate"
#$DelValue = "WAU_BypassListForUsers"
$DelKey = ""
$DelValue = ""
Expand Down

0 comments on commit e16c12e

Please sign in to comment.