@ -2,8 +2,8 @@
. SYNOPSIS
Sophia Script is a PowerShell module for Windows 10 & Windows 11 fine-tuning and automating the routine tasks
Version : v5 . 2 . 14
Date : 19 . 09 . 2021
Version : v5 . 2 . 15
Date : 05 . 10 . 2021
Copyright ( c ) 2014 – 2021 farag
Copyright ( c ) 2019 – 2021 farag & Inestic
@ -135,7 +135,11 @@ function Checkings
[Net.ServicePointManager] :: SecurityProtocol = [Net.SecurityProtocolType] :: Tls12
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json
$LatestRelease = ( Invoke-RestMethod -Uri " https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json " -UseBasicParsing ) . Sophia_Script_Windows_10_LTSC
$Parameters = @ {
Uri = " https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json "
UseBasicParsing = $true
}
$LatestRelease = ( Invoke-RestMethod @Parameters ) . Sophia_Script_Windows_10_LTSC
$CurrentRelease = ( Get-Module -Name Sophia ) . Version . ToString ( )
switch ( [System.Version] $LatestRelease -gt [System.Version] $CurrentRelease )
{
@ -206,6 +210,9 @@ function Checkings
$Script:ControlledFolderAccess = $false
}
}
# Save all opened folders in order to restore them after File Explorer restart
$Script:OpenedFolders = { ( New-Object -ComObject Shell . Application ) . Windows ( ) | ForEach-Object -Process { $_ . Document . Folder . Self . Path } } . Invoke ( )
}
#endregion Checkings
@ -484,7 +491,7 @@ function FeedbackFrequency
}
" Automatically "
{
Remove-Item -Path HKCU : \ SOFTWARE \ Microsoft \ Siuf \ Rules -Force -ErrorAction SilentlyContinu e
Remove-Item -Path HKCU : \ SOFTWARE \ Microsoft \ Siuf \ Rules -Force -ErrorAction Ignor e
}
}
}
@ -809,12 +816,12 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Show window, if minimized
[WinAPI.ForegroundWindow] :: ShowWindowAsync ( $_ . MainWindowHandle , 10 )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Force move the console window to the foreground
[WinAPI.ForegroundWindow] :: SetForegroundWindow ( $_ . MainWindowHandle )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Emulate the Backspace key sending
[System.Windows.Forms.SendKeys] :: SendWait ( " {BACKSPACE 1} " )
@ -1251,11 +1258,11 @@ function MergeConflicts
{
" Show "
{
New-ItemProperty -Path HKCU : \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced -Name HideMergeConflicts -PropertyType DWord -Value 1 -Force
New-ItemProperty -Path HKCU : \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced -Name HideMergeConflicts -PropertyType DWord -Value 0 -Force
}
" Hide "
{
New-ItemProperty -Path HKCU : \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced -Name HideMergeConflicts -PropertyType DWord -Value 0 -Force
New-ItemProperty -Path HKCU : \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced -Name HideMergeConflicts -PropertyType DWord -Value 1 -Force
}
}
}
@ -1588,24 +1595,6 @@ function 3DObjects
Remove-ItemProperty -Path " HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{31C0DD25-9439-4F12-BF41-7FF4EDA38722}\PropertyBag " -Name ThisPCPolicy -Force -ErrorAction Ignore
}
}
# Save all opened folders in order to restore them after File Explorer restart
Clear-Variable -Name OpenedFolders -Force -ErrorAction Ignore
$OpenedFolders = { ( New-Object -ComObject Shell . Application ) . Windows ( ) | ForEach-Object -Process { $_ . Document . Folder . Self . Path } } . Invoke ( )
# In order for the changes to take effect the File Explorer process has to be restarted
Stop-Process -Name explorer -Force
Start-Sleep -Seconds 3
# Restoring closed folders
foreach ( $OpenedFolder in $OpenedFolders )
{
if ( Test-Path -Path $OpenedFolder )
{
Invoke-Item -Path $OpenedFolder
}
}
}
<#
@ -1988,24 +1977,6 @@ function NotificationAreaIcons
New-ItemProperty -Path HKCU : \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Explorer -Name EnableAutoTray -PropertyType DWord -Value 1 -Force
}
}
# Save all opened folders in order to restore them after File Explorer restart
Clear-Variable -Name OpenedFolders -Force -ErrorAction Ignore
$OpenedFolders = { ( New-Object -ComObject Shell . Application ) . Windows ( ) | ForEach-Object -Process { $_ . Document . Folder . Self . Path } } . Invoke ( )
# In order for the changes to take effect the File Explorer process has to be restarted
Stop-Process -Name explorer -Force
Start-Sleep -Seconds 3
# Restoring closed folders
foreach ( $OpenedFolder in $OpenedFolders )
{
if ( Test-Path -Path $OpenedFolder )
{
Invoke-Item -Path $OpenedFolder
}
}
}
@ -3739,12 +3710,12 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Show window, if minimized
[WinAPI.ForegroundWindow] :: ShowWindowAsync ( $_ . MainWindowHandle , 10 )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Force move the console window to the foreground
[WinAPI.ForegroundWindow] :: SetForegroundWindow ( $_ . MainWindowHandle )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Emulate the Backspace key sending
[System.Windows.Forms.SendKeys] :: SendWait ( " {BACKSPACE 1} " )
@ -4036,18 +4007,17 @@ function WindowsCapabilities
{
" Install "
{
# Check the internet connection
try
{
( Invoke-WebRequest -Uri https : / / www . google . com -UseBasicParsing -DisableKeepAlive -Method Head ) . StatusDescription
# Check the internet connection
$Parameters = @ {
Uri = " https://www.google.com "
Method = " Head "
DisableKeepAlive = $true
UseBasicParsing = $true
}
catch [System.Net.WebException]
if ( -not ( Invoke-RestMethod @Parameters ) . StatusDescription )
{
Write-Warning -Message $Localization . NoInternetConnection
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
return
}
@ -4055,6 +4025,14 @@ function WindowsCapabilities
$ButtonContent = $Localization . Install
$ButtonAdd_Click = { InstallButton }
}
catch [System.Net.WebException]
{
Write-Warning -Message $Localization . NoInternetConnection
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
}
}
" Uninstall "
{
$State = " Installed "
@ -4113,12 +4091,12 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Show window, if minimized
[WinAPI.ForegroundWindow] :: ShowWindowAsync ( $_ . MainWindowHandle , 10 )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Force move the console window to the foreground
[WinAPI.ForegroundWindow] :: SetForegroundWindow ( $_ . MainWindowHandle )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Emulate the Backspace key sending
[System.Windows.Forms.SendKeys] :: SendWait ( " {BACKSPACE 1} " )
@ -4402,14 +4380,26 @@ function IPv6Component
$Enable
)
# Check the internet connection
try
{
if ( ( Invoke-WebRequest -Uri https : / / www . google . com -UseBasicParsing -DisableKeepAlive -Method Head ) . StatusDescription )
# Check the internet connection
$Parameters = @ {
Uri = " https://www.google.com "
Method = " Head "
DisableKeepAlive = $true
UseBasicParsing = $true
}
if ( -not ( Invoke-WebRequest @Parameters ) . StatusDescription )
{
return
}
# Check whether the ISP supports IPv6 protocol using https://ipv6-test.com
$IPv6Test = Invoke-RestMethod -Uri " https://v4v6.ipv6-test.com/api/myip.php?json " | Where-Object -FilterScript { $_ . proto -eq " ipv6 " }
$Parameters = @ {
Uri = " https://v4v6.ipv6-test.com/api/myip.php?json "
UseBasicParsing = $true
}
$IPv6Test = Invoke-RestMethod @Parameters | Where-Object -FilterScript { $_ . proto -eq " ipv6 " }
}
catch [System.Net.WebException]
{
@ -4417,8 +4407,6 @@ function IPv6Component
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
return
}
switch ( $PSCmdlet . ParameterSetName )
@ -5541,24 +5529,6 @@ function WinPrtScrFolder
Remove-ItemProperty -Path " HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders " -Name " {B7BEDE81-DF94-4682-A7D8-57A52620B86F} " -Force -ErrorAction Ignore
}
}
# Save all opened folders in order to restore them after File Explorer restart
Clear-Variable -Name OpenedFolders -Force -ErrorAction Ignore
$OpenedFolders = { ( New-Object -ComObject Shell . Application ) . Windows ( ) | ForEach-Object -Process { $_ . Document . Folder . Self . Path } } . Invoke ( )
# In order for the changes to take effect the File Explorer process has to be restarted
Stop-Process -Name explorer -Force
Start-Sleep -Seconds 3
# Restoring closed folders
foreach ( $OpenedFolder in $OpenedFolders )
{
if ( Test-Path -Path $OpenedFolder )
{
Invoke-Item -Path $OpenedFolder
}
}
}
<#
@ -7175,8 +7145,8 @@ while (`$true)
Remove-ItemProperty -Path " HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel " -Name ShowInActionCenter -Force -ErrorAction Ignore
Unregister-ScheduledTask -TaskName " Windows Cleanup " -Confirm : $false
Unregister-ScheduledTask -TaskName " Windows Cleanup Notification " -Confirm : $false
Unregister-ScheduledTask -TaskName " Windows Cleanup " -Confirm : $false -ErrorAction Ignore
Unregister-ScheduledTask -TaskName " Windows Cleanup Notification " -Confirm : $false -ErrorAction Ignore
Remove-Item -Path Registry :: HKEY_CLASSES_ROOT \ WindowsCleanup -Recurse -Force -ErrorAction Ignore
}
@ -8752,10 +8722,22 @@ function BitmapImageNewContext
{
try
{
if ( ( Invoke-WebRequest -Uri https : / / www . google . com -UseBasicParsing -DisableKeepAlive -Method Head ) . StatusDescription )
# Check the internet connection
$Parameters = @ {
Uri = " https://www.google.com "
Method = " Head "
DisableKeepAlive = $true
UseBasicParsing = $true
}
if ( -not ( Invoke-WebRequest @Parameters ) . StatusDescription )
{
Get-WindowsCapability -Online -Name " Microsoft.Windows.MSPaint* " | Add-WindowsCapability -Online
return
}
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . Patient -Verbose
Get-WindowsCapability -Online -Name " Microsoft.Windows.MSPaint* " | Add-WindowsCapability -Online
}
catch [System.Net.WebException]
{
@ -8763,8 +8745,6 @@ function BitmapImageNewContext
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
return
}
}
}
@ -8833,10 +8813,22 @@ function RichTextDocumentNewContext
{
try
{
if ( ( Invoke-WebRequest -Uri https : / / www . google . com -UseBasicParsing -DisableKeepAlive -Method Head ) . StatusDescription )
# Check the internet connection
$Parameters = @ {
Uri = " https://www.google.com "
Method = " Head "
DisableKeepAlive = $true
UseBasicParsing = $true
}
if ( -not ( Invoke-WebRequest @Parameters ) . StatusDescription )
{
Get-WindowsCapability -Online -Name " Microsoft.Windows.WordPad* " | Add-WindowsCapability -Online
return
}
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . Patient -Verbose
Get-WindowsCapability -Online -Name " Microsoft.Windows.WordPad* " | Add-WindowsCapability -Online
}
catch [System.Net.WebException]
{
@ -8844,8 +8836,6 @@ function RichTextDocumentNewContext
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
return
}
}
}
@ -9083,6 +9073,38 @@ public static void PostMessage()
Set-MpPreference -EnableControlledFolderAccess Enabled
}
# In order for the changes to take effect the File Explorer process has to be restarted
$Title = " "
$Message = $Localization . FileExplorerRestartPrompt
$Yes = $Localization . Yes
$No = $Localization . No
$Options = " & $ No " , " & $ Yes "
$DefaultChoice = 1
$Result = $Host . UI . PromptForChoice ( $Title , $Message , $Options , $DefaultChoice )
switch ( $Result )
{
" 0 "
{
continue
}
" 1 "
{
Stop-Process -Name explorer -Force
Start-Sleep -Seconds 3
# Restoring closed folders
foreach ( $Script:OpenedFolder in $Script:OpenedFolders )
{
if ( Test-Path -Path $Script:OpenedFolder )
{
Invoke-Item -Path $Script:OpenedFolder
}
}
}
}
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . RestartWarning