Browse Source

Fixed a bug in Set-Association function

pull/486/head 6.4.4
Dmitry Nefedov 2 years ago
parent
commit
97ce57829d
  1. 4
      sophia_script_versions.json
  2. 90
      src/Sophia_Script_for_Windows_10/Module/Sophia.psm1
  3. 4
      src/Sophia_Script_for_Windows_10_LTSC_2019/Functions.ps1
  4. 2
      src/Sophia_Script_for_Windows_10_LTSC_2019/Manifest/Sophia.psd1
  5. 92
      src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1
  6. 4
      src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1
  7. 90
      src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1
  8. 90
      src/Sophia_Script_for_Windows_11/Module/Sophia.psm1
  9. 90
      src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1

4
sophia_script_versions.json

@ -1,8 +1,8 @@
{
"Sophia_Script_Windows_10_PowerShell_5_1": "5.16.4",
"Sophia_Script_Windows_10_PowerShell_7": "5.16.4",
"Sophia_Script_Windows_10_LTSC2019": "5.6.3",
"Sophia_Script_Windows_10_LTSC2021": "5.16.3",
"Sophia_Script_Windows_10_LTSC2019": "5.6.4",
"Sophia_Script_Windows_10_LTSC2021": "5.16.4",
"Sophia_Script_Windows_11_PowerShell_5_1": "6.4.4",
"Sophia_Script_Windows_11_PowerShell_7": "6.4.4",
"Sophia_Script_Wrapper": "2.6.5"

90
src/Sophia_Script_for_Windows_10/Module/Sophia.psm1

@ -8964,73 +8964,6 @@ public static int UnloadHive(RegistryHives hive, string subKey)
Add-Type @Signature
}
function Set-Icon
{
Param
(
[Parameter(
Mandatory = $true,
Position = 0
)]
[string]
$ProgId,
[Parameter(
Mandatory = $true,
Position = 1
)]
[string]
$Icon
)
if (-not (Test-Path -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon"))
{
New-Item -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Force
}
New-ItemProperty -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Name "(default)" -PropertyType String -Value $Icon -Force
}
function Remove-UserChoiceKey
{
Param
(
[Parameter(
Mandatory = $true,
Position = 0
)]
[string]
$SubKey
)
[WinAPI.Action]::DeleteKey([Microsoft.Win32.RegistryHive]::CurrentUser,$SubKey)
}
function Set-UserAccessKey
{
Param
(
[Parameter(
Mandatory = $true,
Position = 0
)]
[string]
$SubKey
)
$OpenSubKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($SubKey,'ReadWriteSubTree','TakeOwnership')
if ($OpenSubKey)
{
$Acl = [System.Security.AccessControl.RegistrySecurity]::new()
# Get current user SID
$UserSID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
$Acl.SetSecurityDescriptorSddlForm("O:$UserSID`G:$UserSID`D:AI(D;;DC;;;$UserSID)")
$OpenSubKey.SetAccessControl($Acl)
$OpenSubKey.Close()
}
}
function Write-ExtensionKeys
{
Param
@ -9070,7 +9003,7 @@ public static int UnloadHive(RegistryHives hive, string subKey)
# If ProgId doesn't exist set the specified ProgId for the extensions
# Due to "Set-StrictMode -Version Latest" we have to check everything
if (-not (Get-Variable -Name OrigProgID -ErrorAction Ignore))
if (-not (Get-Variable -Name ProgId -ErrorAction Ignore))
{
if (-not (Test-Path -Path "HKCU:\Software\Classes\$Extension"))
{
@ -9104,7 +9037,7 @@ public static int UnloadHive(RegistryHives hive, string subKey)
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\OpenWithProgids" -Name $ProgID -PropertyType None -Value ([byte[]]@()) -Force
# Removing the UserChoice key
Remove-UserChoiceKey -SubKey "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"
[WinAPI.Action]::DeleteKey([Microsoft.Win32.RegistryHive]::CurrentUser, "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice")
# Setting parameters in UserChoice. The key is being autocreated
if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"))
@ -9122,8 +9055,17 @@ public static int UnloadHive(RegistryHives hive, string subKey)
}
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice" -Name Hash -PropertyType String -Value $ProgHash -Force
# Setting a ban on changing the UserChoice section
Set-UserAccessKey -SubKey "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"
# Setting a block on changing the UserChoice section
$OpenSubKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice", "ReadWriteSubTree", "TakeOwnership")
if ($OpenSubKey)
{
$Acl = [System.Security.AccessControl.RegistrySecurity]::new()
# Get current user SID
$UserSID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
$Acl.SetSecurityDescriptorSddlForm("O:$UserSID`G:$UserSID`D:AI(D;;DC;;;$UserSID)")
$OpenSubKey.SetAccessControl($Acl)
$OpenSubKey.Close()
}
}
function Write-AdditionalKeys
@ -9434,7 +9376,11 @@ public static long MakeLong(uint left, uint right)
if ($Icon)
{
Set-Icon -ProgId $ProgId -Icon $Icon
if (-not (Test-Path -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon"))
{
New-Item -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Force
}
New-ItemProperty -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Name "(default)" -PropertyType String -Value $Icon -Force
}
Write-Information -MessageData "" -InformationAction Continue

4
src/Sophia_Script_for_Windows_10_LTSC_2019/Functions.ps1

@ -2,7 +2,7 @@
.SYNOPSIS
The TAB completion for functions and their arguments
Version: v5.6.3
Version: v5.6.4
Date: 01.04.2023
Copyright (c) 20142023 farag
@ -50,7 +50,7 @@ function Sophia
Clear-Host
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2019 v5.6.3 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows 10 | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2019 v5.6.4 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows 10 | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
Remove-Module -Name Sophia -Force -ErrorAction Ignore
Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force

2
src/Sophia_Script_for_Windows_10_LTSC_2019/Manifest/Sophia.psd1

@ -1,6 +1,6 @@
@{
RootModule = '..\Module\Sophia.psm1'
ModuleVersion = '5.6.3'
ModuleVersion = '5.6.4'
GUID = 'a36a65ca-70f9-43df-856c-3048fc5e7f01'
Author = 'Dmitry "farag" Nefedov'
Copyright = '(c) 2014—2023 farag & Inestic. All rights reserved'

92
src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1

@ -2,7 +2,7 @@
.SYNOPSIS
Sophia Script is a PowerShell module for Windows 10 & Windows 11 fine-tuning and automating the routine tasks
Version: v5.6.3
Version: v5.6.4
Date: 01.04.2023
Copyright (c) 20142023 farag
@ -7296,73 +7296,6 @@ public static int UnloadHive(RegistryHives hive, string subKey)
Add-Type @Signature
}
function Set-Icon
{
Param
(
[Parameter(
Mandatory = $true,
Position = 0
)]
[string]
$ProgId,
[Parameter(
Mandatory = $true,
Position = 1
)]
[string]
$Icon
)
if (-not (Test-Path -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon"))
{
New-Item -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Force
}
New-ItemProperty -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Name "(default)" -PropertyType String -Value $Icon -Force
}
function Remove-UserChoiceKey
{
Param
(
[Parameter(
Mandatory = $true,
Position = 0
)]
[string]
$SubKey
)
[WinAPI.Action]::DeleteKey([Microsoft.Win32.RegistryHive]::CurrentUser,$SubKey)
}
function Set-UserAccessKey
{
Param
(
[Parameter(
Mandatory = $true,
Position = 0
)]
[string]
$SubKey
)
$OpenSubKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($SubKey,'ReadWriteSubTree','TakeOwnership')
if ($OpenSubKey)
{
$Acl = [System.Security.AccessControl.RegistrySecurity]::new()
# Get current user SID
$UserSID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
$Acl.SetSecurityDescriptorSddlForm("O:$UserSID`G:$UserSID`D:AI(D;;DC;;;$UserSID)")
$OpenSubKey.SetAccessControl($Acl)
$OpenSubKey.Close()
}
}
function Write-ExtensionKeys
{
Param
@ -7402,7 +7335,7 @@ public static int UnloadHive(RegistryHives hive, string subKey)
# If ProgId doesn't exist set the specified ProgId for the extensions
# Due to "Set-StrictMode -Version Latest" we have to check everything
if (-not (Get-Variable -Name OrigProgID -ErrorAction Ignore))
if (-not (Get-Variable -Name ProgId -ErrorAction Ignore))
{
if (-not (Test-Path -Path "HKCU:\Software\Classes\$Extension"))
{
@ -7436,7 +7369,7 @@ public static int UnloadHive(RegistryHives hive, string subKey)
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\OpenWithProgids" -Name $ProgID -PropertyType None -Value ([byte[]]@()) -Force
# Removing the UserChoice key
Remove-UserChoiceKey -SubKey "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"
[WinAPI.Action]::DeleteKey([Microsoft.Win32.RegistryHive]::CurrentUser, "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice")
# Setting parameters in UserChoice. The key is being autocreated
if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"))
@ -7454,8 +7387,17 @@ public static int UnloadHive(RegistryHives hive, string subKey)
}
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice" -Name Hash -PropertyType String -Value $ProgHash -Force
# Setting a ban on changing the UserChoice section
Set-UserAccessKey -SubKey "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"
# Setting a block on changing the UserChoice section
$OpenSubKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice", "ReadWriteSubTree", "TakeOwnership")
if ($OpenSubKey)
{
$Acl = [System.Security.AccessControl.RegistrySecurity]::new()
# Get current user SID
$UserSID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
$Acl.SetSecurityDescriptorSddlForm("O:$UserSID`G:$UserSID`D:AI(D;;DC;;;$UserSID)")
$OpenSubKey.SetAccessControl($Acl)
$OpenSubKey.Close()
}
}
function Write-AdditionalKeys
@ -7766,7 +7708,11 @@ public static long MakeLong(uint left, uint right)
if ($Icon)
{
Set-Icon -ProgId $ProgId -Icon $Icon
if (-not (Test-Path -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon"))
{
New-Item -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Force
}
New-ItemProperty -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Name "(default)" -PropertyType String -Value $Icon -Force
}
Write-Information -MessageData "" -InformationAction Continue

4
src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1

@ -2,7 +2,7 @@
.SYNOPSIS
Default preset file for "Sophia Script for Windows 10 LTSC 2019"
Version: v5.6.3
Version: v5.6.4
Date: 01.04.2023
Copyright (c) 20142023 farag
@ -70,7 +70,7 @@ param
Clear-Host
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2019 v5.6.3 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
$Host.UI.RawUI.WindowTitle = "Sophia Script for Windows 10 LTSC 2019 v5.6.4 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows | $([char]0x00A9) farag & Inestic, 2014$([char]0x2013)2023"
Remove-Module -Name Sophia -Force -ErrorAction Ignore
Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force

90
src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1

@ -7921,73 +7921,6 @@ public static int UnloadHive(RegistryHives hive, string subKey)
Add-Type @Signature
}
function Set-Icon
{
Param
(
[Parameter(
Mandatory = $true,
Position = 0
)]
[string]
$ProgId,
[Parameter(
Mandatory = $true,
Position = 1
)]
[string]
$Icon
)
if (-not (Test-Path -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon"))
{
New-Item -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Force
}
New-ItemProperty -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Name "(default)" -PropertyType String -Value $Icon -Force
}
function Remove-UserChoiceKey
{
Param
(
[Parameter(
Mandatory = $true,
Position = 0
)]
[string]
$SubKey
)
[WinAPI.Action]::DeleteKey([Microsoft.Win32.RegistryHive]::CurrentUser,$SubKey)
}
function Set-UserAccessKey
{
Param
(
[Parameter(
Mandatory = $true,
Position = 0
)]
[string]
$SubKey
)
$OpenSubKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($SubKey,'ReadWriteSubTree','TakeOwnership')
if ($OpenSubKey)
{
$Acl = [System.Security.AccessControl.RegistrySecurity]::new()
# Get current user SID
$UserSID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
$Acl.SetSecurityDescriptorSddlForm("O:$UserSID`G:$UserSID`D:AI(D;;DC;;;$UserSID)")
$OpenSubKey.SetAccessControl($Acl)
$OpenSubKey.Close()
}
}
function Write-ExtensionKeys
{
Param
@ -8027,7 +7960,7 @@ public static int UnloadHive(RegistryHives hive, string subKey)
# If ProgId doesn't exist set the specified ProgId for the extensions
# Due to "Set-StrictMode -Version Latest" we have to check everything
if (-not (Get-Variable -Name OrigProgID -ErrorAction Ignore))
if (-not (Get-Variable -Name ProgId -ErrorAction Ignore))
{
if (-not (Test-Path -Path "HKCU:\Software\Classes\$Extension"))
{
@ -8061,7 +7994,7 @@ public static int UnloadHive(RegistryHives hive, string subKey)
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\OpenWithProgids" -Name $ProgID -PropertyType None -Value ([byte[]]@()) -Force
# Removing the UserChoice key
Remove-UserChoiceKey -SubKey "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"
[WinAPI.Action]::DeleteKey([Microsoft.Win32.RegistryHive]::CurrentUser, "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice")
# Setting parameters in UserChoice. The key is being autocreated
if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"))
@ -8079,8 +8012,17 @@ public static int UnloadHive(RegistryHives hive, string subKey)
}
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice" -Name Hash -PropertyType String -Value $ProgHash -Force
# Setting a ban on changing the UserChoice section
Set-UserAccessKey -SubKey "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"
# Setting a block on changing the UserChoice section
$OpenSubKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice", "ReadWriteSubTree", "TakeOwnership")
if ($OpenSubKey)
{
$Acl = [System.Security.AccessControl.RegistrySecurity]::new()
# Get current user SID
$UserSID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
$Acl.SetSecurityDescriptorSddlForm("O:$UserSID`G:$UserSID`D:AI(D;;DC;;;$UserSID)")
$OpenSubKey.SetAccessControl($Acl)
$OpenSubKey.Close()
}
}
function Write-AdditionalKeys
@ -8391,7 +8333,11 @@ public static long MakeLong(uint left, uint right)
if ($Icon)
{
Set-Icon -ProgId $ProgId -Icon $Icon
if (-not (Test-Path -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon"))
{
New-Item -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Force
}
New-ItemProperty -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Name "(default)" -PropertyType String -Value $Icon -Force
}
Write-Information -MessageData "" -InformationAction Continue

90
src/Sophia_Script_for_Windows_11/Module/Sophia.psm1

@ -8481,73 +8481,6 @@ public static int UnloadHive(RegistryHives hive, string subKey)
Add-Type @Signature
}
function Set-Icon
{
Param
(
[Parameter(
Mandatory = $true,
Position = 0
)]
[string]
$ProgId,
[Parameter(
Mandatory = $true,
Position = 1
)]
[string]
$Icon
)
if (-not (Test-Path -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon"))
{
New-Item -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Force
}
New-ItemProperty -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Name "(default)" -PropertyType String -Value $Icon -Force
}
function Remove-UserChoiceKey
{
Param
(
[Parameter(
Mandatory = $true,
Position = 0
)]
[string]
$SubKey
)
[WinAPI.Action]::DeleteKey([Microsoft.Win32.RegistryHive]::CurrentUser,$SubKey)
}
function Set-UserAccessKey
{
Param
(
[Parameter(
Mandatory = $true,
Position = 0
)]
[string]
$SubKey
)
$OpenSubKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($SubKey,'ReadWriteSubTree','TakeOwnership')
if ($OpenSubKey)
{
$Acl = [System.Security.AccessControl.RegistrySecurity]::new()
# Get current user SID
$UserSID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
$Acl.SetSecurityDescriptorSddlForm("O:$UserSID`G:$UserSID`D:AI(D;;DC;;;$UserSID)")
$OpenSubKey.SetAccessControl($Acl)
$OpenSubKey.Close()
}
}
function Write-ExtensionKeys
{
Param
@ -8587,7 +8520,7 @@ public static int UnloadHive(RegistryHives hive, string subKey)
# If ProgId doesn't exist set the specified ProgId for the extensions
# Due to "Set-StrictMode -Version Latest" we have to check everything
if (-not (Get-Variable -Name OrigProgID -ErrorAction Ignore))
if (-not (Get-Variable -Name ProgId -ErrorAction Ignore))
{
if (-not (Test-Path -Path "HKCU:\Software\Classes\$Extension"))
{
@ -8621,7 +8554,7 @@ public static int UnloadHive(RegistryHives hive, string subKey)
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\OpenWithProgids" -Name $ProgID -PropertyType None -Value ([byte[]]@()) -Force
# Removing the UserChoice key
Remove-UserChoiceKey -SubKey "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"
[WinAPI.Action]::DeleteKey([Microsoft.Win32.RegistryHive]::CurrentUser, "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice")
# Setting parameters in UserChoice. The key is being autocreated
if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"))
@ -8639,8 +8572,17 @@ public static int UnloadHive(RegistryHives hive, string subKey)
}
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice" -Name Hash -PropertyType String -Value $ProgHash -Force
# Setting a ban on changing the UserChoice section
Set-UserAccessKey -SubKey "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"
# Setting a block on changing the UserChoice section
$OpenSubKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice", "ReadWriteSubTree", "TakeOwnership")
if ($OpenSubKey)
{
$Acl = [System.Security.AccessControl.RegistrySecurity]::new()
# Get current user SID
$UserSID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
$Acl.SetSecurityDescriptorSddlForm("O:$UserSID`G:$UserSID`D:AI(D;;DC;;;$UserSID)")
$OpenSubKey.SetAccessControl($Acl)
$OpenSubKey.Close()
}
}
function Write-AdditionalKeys
@ -8951,7 +8893,11 @@ public static long MakeLong(uint left, uint right)
if ($Icon)
{
Set-Icon -ProgId $ProgId -Icon $Icon
if (-not (Test-Path -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon"))
{
New-Item -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Force
}
New-ItemProperty -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Name "(default)" -PropertyType String -Value $Icon -Force
}
Write-Information -MessageData "" -InformationAction Continue

90
src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1

@ -8489,73 +8489,6 @@ public static int UnloadHive(RegistryHives hive, string subKey)
Add-Type @Signature
}
function Set-Icon
{
Param
(
[Parameter(
Mandatory = $true,
Position = 0
)]
[string]
$ProgId,
[Parameter(
Mandatory = $true,
Position = 1
)]
[string]
$Icon
)
if (-not (Test-Path -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon"))
{
New-Item -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Force
}
New-ItemProperty -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Name "(default)" -PropertyType String -Value $Icon -Force
}
function Remove-UserChoiceKey
{
Param
(
[Parameter(
Mandatory = $true,
Position = 0
)]
[string]
$SubKey
)
[WinAPI.Action]::DeleteKey([Microsoft.Win32.RegistryHive]::CurrentUser,$SubKey)
}
function Set-UserAccessKey
{
Param
(
[Parameter(
Mandatory = $true,
Position = 0
)]
[string]
$SubKey
)
$OpenSubKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($SubKey,'ReadWriteSubTree','TakeOwnership')
if ($OpenSubKey)
{
$Acl = [System.Security.AccessControl.RegistrySecurity]::new()
# Get current user SID
$UserSID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
$Acl.SetSecurityDescriptorSddlForm("O:$UserSID`G:$UserSID`D:AI(D;;DC;;;$UserSID)")
$OpenSubKey.SetAccessControl($Acl)
$OpenSubKey.Close()
}
}
function Write-ExtensionKeys
{
Param
@ -8595,7 +8528,7 @@ public static int UnloadHive(RegistryHives hive, string subKey)
# If ProgId doesn't exist set the specified ProgId for the extensions
# Due to "Set-StrictMode -Version Latest" we have to check everything
if (-not (Get-Variable -Name OrigProgID -ErrorAction Ignore))
if (-not (Get-Variable -Name ProgId -ErrorAction Ignore))
{
if (-not (Test-Path -Path "HKCU:\Software\Classes\$Extension"))
{
@ -8629,7 +8562,7 @@ public static int UnloadHive(RegistryHives hive, string subKey)
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\OpenWithProgids" -Name $ProgID -PropertyType None -Value ([byte[]]@()) -Force
# Removing the UserChoice key
Remove-UserChoiceKey -SubKey "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"
[WinAPI.Action]::DeleteKey([Microsoft.Win32.RegistryHive]::CurrentUser, "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice")
# Setting parameters in UserChoice. The key is being autocreated
if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"))
@ -8647,8 +8580,17 @@ public static int UnloadHive(RegistryHives hive, string subKey)
}
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice" -Name Hash -PropertyType String -Value $ProgHash -Force
# Setting a ban on changing the UserChoice section
Set-UserAccessKey -SubKey "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"
# Setting a block on changing the UserChoice section
$OpenSubKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice", "ReadWriteSubTree", "TakeOwnership")
if ($OpenSubKey)
{
$Acl = [System.Security.AccessControl.RegistrySecurity]::new()
# Get current user SID
$UserSID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
$Acl.SetSecurityDescriptorSddlForm("O:$UserSID`G:$UserSID`D:AI(D;;DC;;;$UserSID)")
$OpenSubKey.SetAccessControl($Acl)
$OpenSubKey.Close()
}
}
function Write-AdditionalKeys
@ -8959,7 +8901,11 @@ public static long MakeLong(uint left, uint right)
if ($Icon)
{
Set-Icon -ProgId $ProgId -Icon $Icon
if (-not (Test-Path -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon"))
{
New-Item -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Force
}
New-ItemProperty -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Name "(default)" -PropertyType String -Value $Icon -Force
}
Write-Information -MessageData "" -InformationAction Continue

Loading…
Cancel
Save