From c6a4018f90807433fb453d836f993b8aa88e1f71 Mon Sep 17 00:00:00 2001 From: Dmitry Nefedov Date: Sun, 27 Apr 2025 22:00:13 +0300 Subject: [PATCH] Fixed Export-Associations function --- .../Module/Sophia.psm1 | 80 +++++-------------- src/Sophia_Script_for_Windows_10/Sophia.ps1 | 9 +-- .../Module/Sophia.psm1 | 29 ++++--- .../Sophia.ps1 | 1 + .../Module/Sophia.psm1 | 29 ++++--- .../Sophia.ps1 | 1 + .../Module/Sophia.psm1 | 80 +++++-------------- .../Sophia.ps1 | 9 +-- .../Module/Sophia.psm1 | 29 ++++--- .../Module/Sophia.psm1 | 29 ++++--- .../Module/Sophia.psm1 | 29 ++++--- 11 files changed, 144 insertions(+), 181 deletions(-) diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index 5546008b..439f441a 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -2368,57 +2368,6 @@ function BingSearch } } } - -<# - .SYNOPSIS - Microsoft account-related notifications on Start Menu - - .PARAMETER Hide - Do not show Microsoft account-related notifications on Start Menu in Start menu - - .PARAMETER Show - Show Microsoft account-related notifications on Start Menu in Start menu - - .EXAMPLE - StartAccountNotifications -Hide - - .EXAMPLE - StartAccountNotifications -Show - - .NOTES - Current user -#> -function StartAccountNotifications -{ - param - ( - [Parameter( - Mandatory = $true, - ParameterSetName = "Hide" - )] - [switch] - $Hide, - - [Parameter( - Mandatory = $true, - ParameterSetName = "Show" - )] - [switch] - $Show - ) - - switch ($PSCmdlet.ParameterSetName) - { - "Hide" - { - New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Start_AccountNotifications -PropertyType DWord -Value 0 -Force - } - "Show" - { - Remove-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Start_AccountNotifications -Force -ErrorAction Ignore - } - } -} #endregion Privacy & Telemetry #region UI & Personalization @@ -9666,9 +9615,12 @@ function Export-Associations [xml]$XML = Get-Content -Path "$env:TEMP\Application_Associations.xml" -Encoding UTF8 -Force $XML.DefaultAssociations.Association | ForEach-Object -Process { + # Clear varibale not to begin double "\" char + $ProgramPath, $Icon = $null + if ($AppxProgIds -contains $_.ProgId) { - # if ProgId is a UWP app + # ProgId is a UWP app # ProgrammPath if (Test-Path -Path "HKCU:\Software\Classes\$($_.ProgId)\Shell\Open\Command") { @@ -9818,8 +9770,6 @@ function Export-Associations $AllJSON += $JSON } - Clear-Variable -Name ProgramPath, Icon -ErrorAction Ignore - # Save in UTF-8 without BOM $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\Application_Associations.json" -Encoding Default -Force @@ -14200,14 +14150,24 @@ function CABInstallContext { "Show" { - if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command)) + if ([Microsoft.Win32.Registry]::GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cab\UserChoice", "ProgId", $null) -eq "CABFolder") { - New-Item -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Force + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Force + } + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Name "(default)" -PropertyType String -Value "cmd /c DISM.exe /Online /Add-Package /PackagePath:`"%1`" /NoRestart & pause" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name MUIVerb -PropertyType String -Value "@shell32.dll,-10210" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name HasLUAShield -PropertyType String -Value "" -Force + } + else + { + Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -Verbose + Write-Error -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + + return } - $Value = "cmd /c DISM.exe /Online /Add-Package /PackagePath:`"%1`" /NoRestart & pause" - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Name "(default)" -PropertyType String -Value $Value -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name MUIVerb -PropertyType String -Value "@shell32.dll,-10210" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name HasLUAShield -PropertyType String -Value "" -Force } "Hide" { diff --git a/src/Sophia_Script_for_Windows_10/Sophia.ps1 b/src/Sophia_Script_for_Windows_10/Sophia.ps1 index b8701f90..85235e1a 100644 --- a/src/Sophia_Script_for_Windows_10/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10/Sophia.ps1 @@ -304,14 +304,6 @@ BingSearch -Disable # Enable Bing search in Start Menu (default value) # Включить поиск через Bing в меню "Пуск" (значение по умолчанию) # BingSearch -Enable - -# Do not show Microsoft account-related notifications on Start Menu in Start menu -# Не показывать в меню "Пуск" уведомления, связанные с учетной записью Microsoft -StartAccountNotifications -Hide - -# Show Microsoft account-related notifications on Start Menu in Start menu (default value) -# Переодически показывать в меню "Пуск" уведомления, связанные с учетной записью Microsoft (значение по умолчанию) -# StartAccountNotifications -Show #endregion Privacy & Telemetry #region UI & Personalization @@ -405,6 +397,7 @@ RecycleBinDeleteConfirmation -Enable # Hide user folders in "This PC" # Скрыть пользовательские папки в "Этот компьютер" +UserFolders -ThreeDObjects Hide # UserFolders -ThreeDObjects Hide -Desktop Hide -Documents Hide -Downloads Hide -Music Hide -Pictures Hide -Videos Hide # Show user folders in "This PC" (default value) diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 index f69a5cab..36e5c1f3 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 @@ -7955,9 +7955,12 @@ function Export-Associations [xml]$XML = Get-Content -Path "$env:TEMP\Application_Associations.xml" -Encoding UTF8 -Force $XML.DefaultAssociations.Association | ForEach-Object -Process { + # Clear varibale not to begin double "\" char + $ProgramPath, $Icon = $null + if ($AppxProgIds -contains $_.ProgId) { - # if ProgId is a UWP app + # ProgId is a UWP app # ProgrammPath if (Test-Path -Path "HKCU:\Software\Classes\$($_.ProgId)\Shell\Open\Command") { @@ -8107,8 +8110,6 @@ function Export-Associations $AllJSON += $JSON } - Clear-Variable -Name ProgramPath, Icon -ErrorAction Ignore - # Save in UTF-8 without BOM $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\Application_Associations.json" -Encoding Default -Force @@ -10837,14 +10838,24 @@ function CABInstallContext { "Show" { - if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command)) + if ([Microsoft.Win32.Registry]::GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cab\UserChoice", "ProgId", $null) -eq "CABFolder") + { + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Force + } + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Name "(default)" -PropertyType String -Value "cmd /c DISM.exe /Online /Add-Package /PackagePath:`"%1`" /NoRestart & pause" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name MUIVerb -PropertyType String -Value "@shell32.dll,-10210" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name HasLUAShield -PropertyType String -Value "" -Force + } + else { - New-Item -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Force + Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -Verbose + Write-Error -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + + return } - $Value = "cmd /c DISM.exe /Online /Add-Package /PackagePath:`"%1`" /NoRestart & pause" - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Name "(default)" -PropertyType String -Value $Value -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name MUIVerb -PropertyType String -Value "@shell32.dll,-10210" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name HasLUAShield -PropertyType String -Value "" -Force } "Hide" { diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 b/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 index 9b516a4d..d1845793 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1 @@ -326,6 +326,7 @@ RecycleBinDeleteConfirmation -Enable # Hide user folders in "This PC" # Скрыть пользовательские папки в "Этот компьютер" +UserFolders -ThreeDObjects Hide # UserFolders -ThreeDObjects Hide -Desktop Hide -Documents Hide -Downloads Hide -Music Hide -Pictures Hide -Videos Hide # Show user folders in "This PC" (default value) diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 index dc9a1304..d13226ca 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 @@ -8592,9 +8592,12 @@ function Export-Associations [xml]$XML = Get-Content -Path "$env:TEMP\Application_Associations.xml" -Encoding UTF8 -Force $XML.DefaultAssociations.Association | ForEach-Object -Process { + # Clear varibale not to begin double "\" char + $ProgramPath, $Icon = $null + if ($AppxProgIds -contains $_.ProgId) { - # if ProgId is a UWP app + # ProgId is a UWP app # ProgrammPath if (Test-Path -Path "HKCU:\Software\Classes\$($_.ProgId)\Shell\Open\Command") { @@ -8744,8 +8747,6 @@ function Export-Associations $AllJSON += $JSON } - Clear-Variable -Name ProgramPath, Icon -ErrorAction Ignore - # Save in UTF-8 without BOM $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\Application_Associations.json" -Encoding Default -Force @@ -12156,14 +12157,24 @@ function CABInstallContext { "Show" { - if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command)) + if ([Microsoft.Win32.Registry]::GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cab\UserChoice", "ProgId", $null) -eq "CABFolder") + { + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Force + } + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Name "(default)" -PropertyType String -Value "cmd /c DISM.exe /Online /Add-Package /PackagePath:`"%1`" /NoRestart & pause" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name MUIVerb -PropertyType String -Value "@shell32.dll,-10210" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name HasLUAShield -PropertyType String -Value "" -Force + } + else { - New-Item -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Force + Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -Verbose + Write-Error -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + + return } - $Value = "cmd /c DISM.exe /Online /Add-Package /PackagePath:`"%1`" /NoRestart & pause" - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Name "(default)" -PropertyType String -Value $Value -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name MUIVerb -PropertyType String -Value "@shell32.dll,-10210" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name HasLUAShield -PropertyType String -Value "" -Force } "Hide" { diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 b/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 index 69bcbabc..f7bd84c1 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1 @@ -358,6 +358,7 @@ RecycleBinDeleteConfirmation -Enable # Hide user folders in "This PC" # Скрыть пользовательские папки в "Этот компьютер" +UserFolders -ThreeDObjects Hide # UserFolders -ThreeDObjects Hide -Desktop Hide -Documents Hide -Downloads Hide -Music Hide -Pictures Hide -Videos Hide # Show user folders in "This PC" (default value) diff --git a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 index a507a672..2ca9cc98 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 @@ -2400,57 +2400,6 @@ function BingSearch } } } - -<# - .SYNOPSIS - Microsoft account-related notifications on Start Menu - - .PARAMETER Hide - Do not show Microsoft account-related notifications on Start Menu in Start menu - - .PARAMETER Show - Show Microsoft account-related notifications on Start Menu in Start menu - - .EXAMPLE - StartAccountNotifications -Hide - - .EXAMPLE - StartAccountNotifications -Show - - .NOTES - Current user -#> -function StartAccountNotifications -{ - param - ( - [Parameter( - Mandatory = $true, - ParameterSetName = "Hide" - )] - [switch] - $Hide, - - [Parameter( - Mandatory = $true, - ParameterSetName = "Show" - )] - [switch] - $Show - ) - - switch ($PSCmdlet.ParameterSetName) - { - "Hide" - { - New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Start_AccountNotifications -PropertyType DWord -Value 0 -Force - } - "Show" - { - Remove-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name Start_AccountNotifications -Force -ErrorAction Ignore - } - } -} #endregion Privacy & Telemetry #region UI & Personalization @@ -9700,9 +9649,12 @@ function Export-Associations [xml]$XML = Get-Content -Path "$env:TEMP\Application_Associations.xml" -Encoding utf8 -Force $XML.DefaultAssociations.Association | ForEach-Object -Process { + # Clear varibale not to begin double "\" char + $ProgramPath, $Icon = $null + if ($AppxProgIds -contains $_.ProgId) { - # if ProgId is a UWP app + # ProgId is a UWP app # ProgrammPath if (Test-Path -Path "HKCU:\Software\Classes\$($_.ProgId)\Shell\Open\Command") { @@ -9852,8 +9804,6 @@ function Export-Associations $AllJSON += $JSON } - Clear-Variable -Name ProgramPath, Icon -ErrorAction Ignore - # Save in UTF-8 without BOM $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\Application_Associations.json" -Encoding utf8NoBOM -Force @@ -14244,14 +14194,24 @@ function CABInstallContext { "Show" { - if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command)) + if ([Microsoft.Win32.Registry]::GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cab\UserChoice", "ProgId", $null) -eq "CABFolder") { - New-Item -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Force + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Force + } + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Name "(default)" -PropertyType String -Value "cmd /c DISM.exe /Online /Add-Package /PackagePath:`"%1`" /NoRestart & pause" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name MUIVerb -PropertyType String -Value "@shell32.dll,-10210" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name HasLUAShield -PropertyType String -Value "" -Force + } + else + { + Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -Verbose + Write-Error -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + + return } - $Value = "cmd /c DISM.exe /Online /Add-Package /PackagePath:`"%1`" /NoRestart & pause" - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Name "(default)" -PropertyType String -Value $Value -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name MUIVerb -PropertyType String -Value "@shell32.dll,-10210" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name HasLUAShield -PropertyType String -Value "" -Force } "Hide" { diff --git a/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 b/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 index e0da0b57..101ba744 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1 @@ -308,14 +308,6 @@ BingSearch -Disable # Enable Bing search in Start Menu (default value) # Включить поиск через Bing в меню "Пуск" (значение по умолчанию) # BingSearch -Enable - -# Do not show Microsoft account-related notifications on Start Menu in Start menu -# Не показывать в меню "Пуск" уведомления, связанные с учетной записью Microsoft -StartAccountNotifications -Hide - -# Show Microsoft account-related notifications on Start Menu in Start menu (default value) -# Переодически показывать в меню "Пуск" уведомления, связанные с учетной записью Microsoft (значение по умолчанию) -# StartAccountNotifications -Show #endregion Privacy & Telemetry #region UI & Personalization @@ -409,6 +401,7 @@ RecycleBinDeleteConfirmation -Enable # Hide user folders in "This PC" # Скрыть пользовательские папки в "Этот компьютер" +UserFolders -ThreeDObjects Hide # UserFolders -ThreeDObjects Hide -Desktop Hide -Documents Hide -Downloads Hide -Music Hide -Pictures Hide -Videos Hide # Show user folders in "This PC" (default value) diff --git a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 index 1ea45005..bbf2c360 100644 --- a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 @@ -9219,9 +9219,12 @@ function Export-Associations [xml]$XML = Get-Content -Path "$env:TEMP\Application_Associations.xml" -Encoding UTF8 -Force $XML.DefaultAssociations.Association | ForEach-Object -Process { + # Clear varibale not to begin double "\" char + $ProgramPath, $Icon = $null + if ($AppxProgIds -contains $_.ProgId) { - # if ProgId is a UWP app + # ProgId is a UWP app # ProgrammPath if (Test-Path -Path "HKCU:\Software\Classes\$($_.ProgId)\Shell\Open\Command") { @@ -9371,8 +9374,6 @@ function Export-Associations $AllJSON += $JSON } - Clear-Variable -Name ProgramPath, Icon -ErrorAction Ignore - # Save in UTF-8 without BOM $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\Application_Associations.json" -Encoding Default -Force @@ -13326,14 +13327,24 @@ function CABInstallContext { "Show" { - if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command)) + if ([Microsoft.Win32.Registry]::GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cab\UserChoice", "ProgId", $null) -eq "CABFolder") + { + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Force + } + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Name "(default)" -PropertyType String -Value "cmd /c DISM.exe /Online /Add-Package /PackagePath:`"%1`" /NoRestart & pause" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name MUIVerb -PropertyType String -Value "@shell32.dll,-10210" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name HasLUAShield -PropertyType String -Value "" -Force + } + else { - New-Item -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Force + Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -Verbose + Write-Error -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + + return } - $Value = "cmd /c DISM.exe /Online /Add-Package /PackagePath:`"%1`" /NoRestart & pause" - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Name "(default)" -PropertyType String -Value $Value -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name MUIVerb -PropertyType String -Value "@shell32.dll,-10210" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name HasLUAShield -PropertyType String -Value "" -Force } "Hide" { diff --git a/src/Sophia_Script_for_Windows_11_LTSC_2024/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11_LTSC_2024/Module/Sophia.psm1 index 0eba6391..a3e4c4e3 100644 --- a/src/Sophia_Script_for_Windows_11_LTSC_2024/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11_LTSC_2024/Module/Sophia.psm1 @@ -8747,9 +8747,12 @@ function Export-Associations [xml]$XML = Get-Content -Path "$env:TEMP\Application_Associations.xml" -Encoding UTF8 -Force $XML.DefaultAssociations.Association | ForEach-Object -Process { + # Clear varibale not to begin double "\" char + $ProgramPath, $Icon = $null + if ($AppxProgIds -contains $_.ProgId) { - # if ProgId is a UWP app + # ProgId is a UWP app # ProgrammPath if (Test-Path -Path "HKCU:\Software\Classes\$($_.ProgId)\Shell\Open\Command") { @@ -8899,8 +8902,6 @@ function Export-Associations $AllJSON += $JSON } - Clear-Variable -Name ProgramPath, Icon -ErrorAction Ignore - # Save in UTF-8 without BOM $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\Application_Associations.json" -Encoding Default -Force @@ -12651,14 +12652,24 @@ function CABInstallContext { "Show" { - if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command)) + if ([Microsoft.Win32.Registry]::GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cab\UserChoice", "ProgId", $null) -eq "CABFolder") + { + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Force + } + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Name "(default)" -PropertyType String -Value "cmd /c DISM.exe /Online /Add-Package /PackagePath:`"%1`" /NoRestart & pause" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name MUIVerb -PropertyType String -Value "@shell32.dll,-10210" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name HasLUAShield -PropertyType String -Value "" -Force + } + else { - New-Item -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Force + Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -Verbose + Write-Error -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + + return } - $Value = "cmd /c DISM.exe /Online /Add-Package /PackagePath:`"%1`" /NoRestart & pause" - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Name "(default)" -PropertyType String -Value $Value -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name MUIVerb -PropertyType String -Value "@shell32.dll,-10210" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name HasLUAShield -PropertyType String -Value "" -Force } "Hide" { diff --git a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 index c4b42c7c..977ff6d5 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 @@ -9253,9 +9253,12 @@ function Export-Associations [xml]$XML = Get-Content -Path "$env:TEMP\Application_Associations.xml" -Encoding UTF8 -Force $XML.DefaultAssociations.Association | ForEach-Object -Process { + # Clear varibale not to begin double "\" char + $ProgramPath, $Icon = $null + if ($AppxProgIds -contains $_.ProgId) { - # if ProgId is a UWP app + # ProgId is a UWP app # ProgrammPath if (Test-Path -Path "HKCU:\Software\Classes\$($_.ProgId)\Shell\Open\Command") { @@ -9405,8 +9408,6 @@ function Export-Associations $AllJSON += $JSON } - Clear-Variable -Name ProgramPath, Icon -ErrorAction Ignore - # Save in UTF-8 without BOM $AllJSON | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\..\Application_Associations.json" -Encoding utf8NoBOM -Force @@ -13370,14 +13371,24 @@ function CABInstallContext { "Show" { - if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command)) + if ([Microsoft.Win32.Registry]::GetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.cab\UserChoice", "ProgId", $null) -eq "CABFolder") + { + if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command)) + { + New-Item -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Force + } + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Name "(default)" -PropertyType String -Value "cmd /c DISM.exe /Online /Add-Package /PackagePath:`"%1`" /NoRestart & pause" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name MUIVerb -PropertyType String -Value "@shell32.dll,-10210" -Force + New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name HasLUAShield -PropertyType String -Value "" -Force + } + else { - New-Item -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Force + Write-Information -MessageData "" -InformationAction Continue + Write-Verbose -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -Verbose + Write-Error -Message ($Localization.Skipped -f $MyInvocation.Line.Trim()) -ErrorAction SilentlyContinue + + return } - $Value = "cmd /c DISM.exe /Online /Add-Package /PackagePath:`"%1`" /NoRestart & pause" - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas\Command -Name "(default)" -PropertyType String -Value $Value -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name MUIVerb -PropertyType String -Value "@shell32.dll,-10210" -Force - New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\CABFolder\Shell\runas -Name HasLUAShield -PropertyType String -Value "" -Force } "Hide" {