@ -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 ) 2014 — 2023 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