Skip to content

Commit 97ce578

Browse files
committed
Fixed a bug in Set-Association function
1 parent 2099e6f commit 97ce578

File tree

9 files changed

+98
-368
lines changed

9 files changed

+98
-368
lines changed

sophia_script_versions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"Sophia_Script_Windows_10_PowerShell_5_1": "5.16.4",
33
"Sophia_Script_Windows_10_PowerShell_7": "5.16.4",
4-
"Sophia_Script_Windows_10_LTSC2019": "5.6.3",
5-
"Sophia_Script_Windows_10_LTSC2021": "5.16.3",
4+
"Sophia_Script_Windows_10_LTSC2019": "5.6.4",
5+
"Sophia_Script_Windows_10_LTSC2021": "5.16.4",
66
"Sophia_Script_Windows_11_PowerShell_5_1": "6.4.4",
77
"Sophia_Script_Windows_11_PowerShell_7": "6.4.4",
88
"Sophia_Script_Wrapper": "2.6.5"

src/Sophia_Script_for_Windows_10/Module/Sophia.psm1

Lines changed: 18 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -8964,73 +8964,6 @@ public static int UnloadHive(RegistryHives hive, string subKey)
89648964
Add-Type @Signature
89658965
}
89668966

8967-
8968-
function Set-Icon
8969-
{
8970-
Param
8971-
(
8972-
[Parameter(
8973-
Mandatory = $true,
8974-
Position = 0
8975-
8976-
)]
8977-
[string]
8978-
$ProgId,
8979-
8980-
[Parameter(
8981-
Mandatory = $true,
8982-
Position = 1
8983-
)]
8984-
[string]
8985-
$Icon
8986-
)
8987-
8988-
if (-not (Test-Path -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon"))
8989-
{
8990-
New-Item -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Force
8991-
}
8992-
New-ItemProperty -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Name "(default)" -PropertyType String -Value $Icon -Force
8993-
}
8994-
8995-
function Remove-UserChoiceKey
8996-
{
8997-
Param
8998-
(
8999-
[Parameter(
9000-
Mandatory = $true,
9001-
Position = 0
9002-
)]
9003-
[string]
9004-
$SubKey
9005-
)
9006-
9007-
[WinAPI.Action]::DeleteKey([Microsoft.Win32.RegistryHive]::CurrentUser,$SubKey)
9008-
}
9009-
9010-
function Set-UserAccessKey
9011-
{
9012-
Param
9013-
(
9014-
[Parameter(
9015-
Mandatory = $true,
9016-
Position = 0
9017-
)]
9018-
[string]
9019-
$SubKey
9020-
)
9021-
9022-
$OpenSubKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($SubKey,'ReadWriteSubTree','TakeOwnership')
9023-
if ($OpenSubKey)
9024-
{
9025-
$Acl = [System.Security.AccessControl.RegistrySecurity]::new()
9026-
# Get current user SID
9027-
$UserSID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
9028-
$Acl.SetSecurityDescriptorSddlForm("O:$UserSID`G:$UserSID`D:AI(D;;DC;;;$UserSID)")
9029-
$OpenSubKey.SetAccessControl($Acl)
9030-
$OpenSubKey.Close()
9031-
}
9032-
}
9033-
90348967
function Write-ExtensionKeys
90358968
{
90368969
Param
@@ -9070,7 +9003,7 @@ public static int UnloadHive(RegistryHives hive, string subKey)
90709003

90719004
# If ProgId doesn't exist set the specified ProgId for the extensions
90729005
# Due to "Set-StrictMode -Version Latest" we have to check everything
9073-
if (-not (Get-Variable -Name OrigProgID -ErrorAction Ignore))
9006+
if (-not (Get-Variable -Name ProgId -ErrorAction Ignore))
90749007
{
90759008
if (-not (Test-Path -Path "HKCU:\Software\Classes\$Extension"))
90769009
{
@@ -9104,7 +9037,7 @@ public static int UnloadHive(RegistryHives hive, string subKey)
91049037
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\OpenWithProgids" -Name $ProgID -PropertyType None -Value ([byte[]]@()) -Force
91059038

91069039
# Removing the UserChoice key
9107-
Remove-UserChoiceKey -SubKey "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"
9040+
[WinAPI.Action]::DeleteKey([Microsoft.Win32.RegistryHive]::CurrentUser, "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice")
91089041

91099042
# Setting parameters in UserChoice. The key is being autocreated
91109043
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)
91229055
}
91239056
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice" -Name Hash -PropertyType String -Value $ProgHash -Force
91249057

9125-
# Setting a ban on changing the UserChoice section
9126-
Set-UserAccessKey -SubKey "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"
9058+
# Setting a block on changing the UserChoice section
9059+
$OpenSubKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice", "ReadWriteSubTree", "TakeOwnership")
9060+
if ($OpenSubKey)
9061+
{
9062+
$Acl = [System.Security.AccessControl.RegistrySecurity]::new()
9063+
# Get current user SID
9064+
$UserSID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
9065+
$Acl.SetSecurityDescriptorSddlForm("O:$UserSID`G:$UserSID`D:AI(D;;DC;;;$UserSID)")
9066+
$OpenSubKey.SetAccessControl($Acl)
9067+
$OpenSubKey.Close()
9068+
}
91279069
}
91289070

91299071
function Write-AdditionalKeys
@@ -9434,7 +9376,11 @@ public static long MakeLong(uint left, uint right)
94349376

94359377
if ($Icon)
94369378
{
9437-
Set-Icon -ProgId $ProgId -Icon $Icon
9379+
if (-not (Test-Path -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon"))
9380+
{
9381+
New-Item -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Force
9382+
}
9383+
New-ItemProperty -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Name "(default)" -PropertyType String -Value $Icon -Force
94389384
}
94399385

94409386
Write-Information -MessageData "" -InformationAction Continue

src/Sophia_Script_for_Windows_10_LTSC_2019/Functions.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.SYNOPSIS
33
The TAB completion for functions and their arguments
44
5-
Version: v5.6.3
5+
Version: v5.6.4
66
Date: 01.04.2023
77
88
Copyright (c) 2014—2023 farag
@@ -50,7 +50,7 @@ function Sophia
5050

5151
Clear-Host
5252

53-
$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"
53+
$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"
5454

5555
Remove-Module -Name Sophia -Force -ErrorAction Ignore
5656
Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force

src/Sophia_Script_for_Windows_10_LTSC_2019/Manifest/Sophia.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
RootModule = '..\Module\Sophia.psm1'
3-
ModuleVersion = '5.6.3'
3+
ModuleVersion = '5.6.4'
44
GUID = 'a36a65ca-70f9-43df-856c-3048fc5e7f01'
55
Author = 'Dmitry "farag" Nefedov'
66
Copyright = '(c) 2014—2023 farag & Inestic. All rights reserved'

src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1

Lines changed: 19 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.SYNOPSIS
33
Sophia Script is a PowerShell module for Windows 10 & Windows 11 fine-tuning and automating the routine tasks
44
5-
Version: v5.6.3
5+
Version: v5.6.4
66
Date: 01.04.2023
77
88
Copyright (c) 2014—2023 farag
@@ -7296,73 +7296,6 @@ public static int UnloadHive(RegistryHives hive, string subKey)
72967296
Add-Type @Signature
72977297
}
72987298

7299-
7300-
function Set-Icon
7301-
{
7302-
Param
7303-
(
7304-
[Parameter(
7305-
Mandatory = $true,
7306-
Position = 0
7307-
7308-
)]
7309-
[string]
7310-
$ProgId,
7311-
7312-
[Parameter(
7313-
Mandatory = $true,
7314-
Position = 1
7315-
)]
7316-
[string]
7317-
$Icon
7318-
)
7319-
7320-
if (-not (Test-Path -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon"))
7321-
{
7322-
New-Item -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Force
7323-
}
7324-
New-ItemProperty -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Name "(default)" -PropertyType String -Value $Icon -Force
7325-
}
7326-
7327-
function Remove-UserChoiceKey
7328-
{
7329-
Param
7330-
(
7331-
[Parameter(
7332-
Mandatory = $true,
7333-
Position = 0
7334-
)]
7335-
[string]
7336-
$SubKey
7337-
)
7338-
7339-
[WinAPI.Action]::DeleteKey([Microsoft.Win32.RegistryHive]::CurrentUser,$SubKey)
7340-
}
7341-
7342-
function Set-UserAccessKey
7343-
{
7344-
Param
7345-
(
7346-
[Parameter(
7347-
Mandatory = $true,
7348-
Position = 0
7349-
)]
7350-
[string]
7351-
$SubKey
7352-
)
7353-
7354-
$OpenSubKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($SubKey,'ReadWriteSubTree','TakeOwnership')
7355-
if ($OpenSubKey)
7356-
{
7357-
$Acl = [System.Security.AccessControl.RegistrySecurity]::new()
7358-
# Get current user SID
7359-
$UserSID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
7360-
$Acl.SetSecurityDescriptorSddlForm("O:$UserSID`G:$UserSID`D:AI(D;;DC;;;$UserSID)")
7361-
$OpenSubKey.SetAccessControl($Acl)
7362-
$OpenSubKey.Close()
7363-
}
7364-
}
7365-
73667299
function Write-ExtensionKeys
73677300
{
73687301
Param
@@ -7402,7 +7335,7 @@ public static int UnloadHive(RegistryHives hive, string subKey)
74027335

74037336
# If ProgId doesn't exist set the specified ProgId for the extensions
74047337
# Due to "Set-StrictMode -Version Latest" we have to check everything
7405-
if (-not (Get-Variable -Name OrigProgID -ErrorAction Ignore))
7338+
if (-not (Get-Variable -Name ProgId -ErrorAction Ignore))
74067339
{
74077340
if (-not (Test-Path -Path "HKCU:\Software\Classes\$Extension"))
74087341
{
@@ -7436,7 +7369,7 @@ public static int UnloadHive(RegistryHives hive, string subKey)
74367369
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\OpenWithProgids" -Name $ProgID -PropertyType None -Value ([byte[]]@()) -Force
74377370

74387371
# Removing the UserChoice key
7439-
Remove-UserChoiceKey -SubKey "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"
7372+
[WinAPI.Action]::DeleteKey([Microsoft.Win32.RegistryHive]::CurrentUser, "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice")
74407373

74417374
# Setting parameters in UserChoice. The key is being autocreated
74427375
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)
74547387
}
74557388
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice" -Name Hash -PropertyType String -Value $ProgHash -Force
74567389

7457-
# Setting a ban on changing the UserChoice section
7458-
Set-UserAccessKey -SubKey "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice"
7390+
# Setting a block on changing the UserChoice section
7391+
$OpenSubKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\$Extension\UserChoice", "ReadWriteSubTree", "TakeOwnership")
7392+
if ($OpenSubKey)
7393+
{
7394+
$Acl = [System.Security.AccessControl.RegistrySecurity]::new()
7395+
# Get current user SID
7396+
$UserSID = (Get-CimInstance -ClassName Win32_UserAccount | Where-Object -FilterScript {$_.Name -eq $env:USERNAME}).SID
7397+
$Acl.SetSecurityDescriptorSddlForm("O:$UserSID`G:$UserSID`D:AI(D;;DC;;;$UserSID)")
7398+
$OpenSubKey.SetAccessControl($Acl)
7399+
$OpenSubKey.Close()
7400+
}
74597401
}
74607402

74617403
function Write-AdditionalKeys
@@ -7766,7 +7708,11 @@ public static long MakeLong(uint left, uint right)
77667708

77677709
if ($Icon)
77687710
{
7769-
Set-Icon -ProgId $ProgId -Icon $Icon
7711+
if (-not (Test-Path -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon"))
7712+
{
7713+
New-Item -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Force
7714+
}
7715+
New-ItemProperty -Path "HKCU:\Software\Classes\$ProgId\DefaultIcon" -Name "(default)" -PropertyType String -Value $Icon -Force
77707716
}
77717717

77727718
Write-Information -MessageData "" -InformationAction Continue

src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.SYNOPSIS
33
Default preset file for "Sophia Script for Windows 10 LTSC 2019"
44
5-
Version: v5.6.3
5+
Version: v5.6.4
66
Date: 01.04.2023
77
88
Copyright (c) 2014—2023 farag
@@ -70,7 +70,7 @@ param
7070

7171
Clear-Host
7272

73-
$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"
73+
$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"
7474

7575
Remove-Module -Name Sophia -Force -ErrorAction Ignore
7676
Import-Module -Name $PSScriptRoot\Manifest\Sophia.psd1 -PassThru -Force

0 commit comments

Comments
 (0)