@ -2,8 +2,8 @@
. SYNOPSIS
. SYNOPSIS
Sophia Script is a PowerShell module for Windows 10 & Windows 11 fine-tuning and automating the routine tasks
Sophia Script is a PowerShell module for Windows 10 & Windows 11 fine-tuning and automating the routine tasks
Version : v5 . 12 . 3
Version : v5 . 12 . 4
Date : 19 . 09 . 2021
Date : 05 . 10 . 2021
Copyright ( c ) 2014 – 2021 farag
Copyright ( c ) 2014 – 2021 farag
Copyright ( c ) 2019 – 2021 farag & Inestic
Copyright ( c ) 2019 – 2021 farag & Inestic
@ -170,10 +170,13 @@ function Checkings
# Check if the current module version is the latest one
# Check if the current module version is the latest one
try
try
{
{
[Net.ServicePointManager] :: SecurityProtocol = [Net.SecurityProtocolType] :: Tls12
# https://github.com/farag2/Sophia-Script-for-Windows/blob/master/sophia_script_versions.json
# 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_PowerShell_7
$Parameters = @ {
Uri = " https://raw.githubusercontent.com/farag2/Sophia-Script-for-Windows/master/sophia_script_versions.json "
SslProtocol = " Tls13 "
UseBasicParsing = $true
}
$LatestRelease = ( Invoke-RestMethod @Parameters ) . Sophia_Script_Windows_10_PowerShell_7
$CurrentRelease = ( Get-Module -Name Sophia ) . Version . ToString ( )
$CurrentRelease = ( Get-Module -Name Sophia ) . Version . ToString ( )
switch ( [System.Version] $LatestRelease -gt [System.Version] $CurrentRelease )
switch ( [System.Version] $LatestRelease -gt [System.Version] $CurrentRelease )
{
{
@ -247,6 +250,9 @@ function Checkings
$Script:ControlledFolderAccess = $false
$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
#endregion Checkings
@ -858,12 +864,12 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Show window, if minimized
# Show window, if minimized
[WinAPI.ForegroundWindow] :: ShowWindowAsync ( $_ . MainWindowHandle , 10 )
[WinAPI.ForegroundWindow] :: ShowWindowAsync ( $_ . MainWindowHandle , 10 )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Force move the console window to the foreground
# Force move the console window to the foreground
[WinAPI.ForegroundWindow] :: SetForegroundWindow ( $_ . MainWindowHandle )
[WinAPI.ForegroundWindow] :: SetForegroundWindow ( $_ . MainWindowHandle )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Emulate the Backspace key sending
# Emulate the Backspace key sending
[System.Windows.Forms.SendKeys] :: SendWait ( " {BACKSPACE 1} " )
[System.Windows.Forms.SendKeys] :: SendWait ( " {BACKSPACE 1} " )
@ -1320,10 +1326,10 @@ function WhatsNewInWindows
Tailored experiences
Tailored experiences
. PARAMETER Disable
. PARAMETER Disable
Do not let Microsoft offer you tailored expereinces based on the diagnostic data setting you hava chosen
Do not let Microsoft offer you tailored expereinces based on the diagnostic data setting you have chosen
. PARAMETER Enable
. PARAMETER Enable
Let Microsoft offer you tailored expereinces based on the diagnostic data setting you hava chosen
Let Microsoft offer you tailored expereinces based on the diagnostic data setting you have chosen
. EXAMPLE
. EXAMPLE
TailoredExperiences -Disable
TailoredExperiences -Disable
@ -1673,11 +1679,11 @@ function MergeConflicts
{
{
" Show "
" 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 "
" 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
}
}
}
}
}
}
@ -1774,14 +1780,20 @@ function CortanaButton
switch ( $PSCmdlet . ParameterSetName )
switch ( $PSCmdlet . ParameterSetName )
{
{
" Hide "
" Hide "
{
if ( Get-AppxPackage -Name Microsoft . 549981C3F5F10 )
{
{
New-ItemProperty -Path HKCU : \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced -Name ShowCortanaButton -PropertyType DWord -Value 0 -Force
New-ItemProperty -Path HKCU : \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced -Name ShowCortanaButton -PropertyType DWord -Value 0 -Force
}
}
}
" Show "
" Show "
{
if ( Get-AppxPackage -Name Microsoft . 549981C3F5F10 )
{
{
New-ItemProperty -Path HKCU : \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced -Name ShowCortanaButton -PropertyType DWord -Value 1 -Force
New-ItemProperty -Path HKCU : \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced -Name ShowCortanaButton -PropertyType DWord -Value 1 -Force
}
}
}
}
}
}
}
<#
<#
@ -2112,24 +2124,6 @@ function 3DObjects
Remove-ItemProperty -Path " HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{31C0DD25-9439-4F12-BF41-7FF4EDA38722}\PropertyBag " -Name ThisPCPolicy -Force -ErrorAction Ignore
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
}
}
}
}
<#
<#
@ -2563,24 +2557,6 @@ function NotificationAreaIcons
New-ItemProperty -Path HKCU : \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Explorer -Name EnableAutoTray -PropertyType DWord -Value 1 -Force
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
}
}
}
}
<#
<#
@ -2636,24 +2612,6 @@ function MeetNow
New-ItemProperty -Path HKCU : \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ StuckRects3 -Name Settings -PropertyType Binary -Value $Settings -Force
New-ItemProperty -Path HKCU : \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ StuckRects3 -Name Settings -PropertyType Binary -Value $Settings -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
}
}
}
}
<#
<#
@ -3491,7 +3449,7 @@ function AeroShaking
Uninstall OneDrive
Uninstall OneDrive
. PARAMETER Install
. PARAMETER Install
Install OneDrive
Install OneDrive 64 -bit
. EXAMPLE
. EXAMPLE
OneDrive -Uninstall
OneDrive -Uninstall
@ -3619,11 +3577,22 @@ public static bool MarkFileDelete (string sourcefile)
# Save all opened folders in order to restore them after File Explorer restarting
# Save all opened folders in order to restore them after File Explorer restarting
Clear-Variable -Name OpenedFolders -Force -ErrorAction Ignore
Clear-Variable -Name OpenedFolders -Force -ErrorAction Ignore
$OpenedFolders = { ( New-Object -ComObject Shell . Application ) . Windows ( ) | ForEach-Object -Process { $_ . Document . Folder . Self . Path } } . Invoke ( )
$Script: OpenedFolders = { ( New-Object -ComObject Shell . Application ) . Windows ( ) | ForEach-Object -Process { $_ . Document . Folder . Self . Path } } . Invoke ( )
# Terminate the File Explorer process
# Terminate the File Explorer process
New-ItemProperty -Path " HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon " -Name AutoRestartShell -Value 0 -Force
New-ItemProperty -Path " HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon " -Name AutoRestartShell -Value 0 -Force
Stop-Process -Name explorer -Force
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
}
}
New-ItemProperty -Path " HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon " -Name AutoRestartShell -Value 1 -Force
New-ItemProperty -Path " HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon " -Name AutoRestartShell -Value 1 -Force
# Attempt to unregister FileSyncShell64.dll and remove
# Attempt to unregister FileSyncShell64.dll and remove
@ -3675,15 +3644,27 @@ public static bool MarkFileDelete (string sourcefile)
{
{
Write-Information -MessageData " " -InformationAction Continue
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . OneDriveInstalling -Verbose
Write-Verbose -Message $Localization . OneDriveInstalling -Verbose
Start-Process -FilePath $env:SystemRoot \ SysWOW64 \ OneDriveSetup . exe
Start-Process -FilePath $env:SystemRoot \ SysWOW64 \ OneDriveSetup . exe
}
}
else
else
{
{
try
try
{
{
# Downloading the latest OneDrive installer x64
# Check the internet connection
if ( ( Invoke-WebRequest -Uri https : / / www . google . com -UseBasicParsing -DisableKeepAlive -Method Head ) . StatusDescription )
$Parameters = @ {
Uri = " https://www.google.com "
Method = " Head "
SslProtocol = " Tls13 "
DisableKeepAlive = $true
UseBasicParsing = $true
}
if ( -not ( Invoke-WebRequest @Parameters ) . StatusDescription )
{
{
return
}
# Downloading the latest OneDrive installer 64-bit
Write-Information -MessageData " " -InformationAction Continue
Write-Information -MessageData " " -InformationAction Continue
Write-Verbose -Message $Localization . OneDriveDownloading -Verbose
Write-Verbose -Message $Localization . OneDriveDownloading -Verbose
@ -3691,6 +3672,7 @@ public static bool MarkFileDelete (string sourcefile)
# https://go.microsoft.com/fwlink/p/?LinkID=844652
# https://go.microsoft.com/fwlink/p/?LinkID=844652
$Parameters = @ {
$Parameters = @ {
Uri = " https://g.live.com/1rewlive5skydrive/OneDriveProduction "
Uri = " https://g.live.com/1rewlive5skydrive/OneDriveProduction "
SslProtocol = " Tls13 "
UseBasicParsing = $true
UseBasicParsing = $true
Verbose = $true
Verbose = $true
}
}
@ -3704,13 +3686,15 @@ public static bool MarkFileDelete (string sourcefile)
$Parameters = @ {
$Parameters = @ {
Uri = $OneDriveURL
Uri = $OneDriveURL
OutFile = " $ DownloadsFolder\OneDriveSetup.exe "
OutFile = " $ DownloadsFolder\OneDriveSetup.exe "
SslProtocol = " Tls12 "
SslProtocol = " Tls13 "
UseBasicParsing = $true
Verbose = $true
Verbose = $true
}
}
Invoke-WebRequest @Parameters
Invoke-WebRequest @Parameters
Start-Process -FilePath " $ DownloadsFolder\OneDriveSetup.exe "
Start-Process -FilePath " $ DownloadsFolder\OneDriveSetup.exe " -Wait
}
Remove-Item -Path " $ DownloadsFolder\OneDriveSetup.exe " -Force
}
}
catch [System.Net.WebException]
catch [System.Net.WebException]
{
{
@ -3718,12 +3702,11 @@ public static bool MarkFileDelete (string sourcefile)
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
return
}
}
}
}
Get-ScheduledTask -TaskName " Onedrive* Update* " | Enable-ScheduledTask
Get-ScheduledTask -TaskName " Onedrive* Update* " | Enable-ScheduledTask
Get-ScheduledTask -TaskName " Onedrive* Update* " | Start-ScheduledTask
}
}
}
}
}
}
@ -4905,12 +4888,12 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Show window, if minimized
# Show window, if minimized
[WinAPI.ForegroundWindow] :: ShowWindowAsync ( $_ . MainWindowHandle , 10 )
[WinAPI.ForegroundWindow] :: ShowWindowAsync ( $_ . MainWindowHandle , 10 )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Force move the console window to the foreground
# Force move the console window to the foreground
[WinAPI.ForegroundWindow] :: SetForegroundWindow ( $_ . MainWindowHandle )
[WinAPI.ForegroundWindow] :: SetForegroundWindow ( $_ . MainWindowHandle )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Emulate the Backspace key sending
# Emulate the Backspace key sending
[System.Windows.Forms.SendKeys] :: SendWait ( " {BACKSPACE 1} " )
[System.Windows.Forms.SendKeys] :: SendWait ( " {BACKSPACE 1} " )
@ -5220,18 +5203,18 @@ function WindowsCapabilities
{
{
" Install "
" Install "
{
{
# Check the internet connection
try
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 "
SslProtocol = " Tls13 "
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
return
}
}
@ -5239,6 +5222,14 @@ function WindowsCapabilities
$ButtonContent = $Localization . Install
$ButtonContent = $Localization . Install
$ButtonAdd_Click = { InstallButton }
$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 "
" Uninstall "
{
{
$State = " Installed "
$State = " Installed "
@ -5297,12 +5288,12 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Show window, if minimized
# Show window, if minimized
[WinAPI.ForegroundWindow] :: ShowWindowAsync ( $_ . MainWindowHandle , 10 )
[WinAPI.ForegroundWindow] :: ShowWindowAsync ( $_ . MainWindowHandle , 10 )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Force move the console window to the foreground
# Force move the console window to the foreground
[WinAPI.ForegroundWindow] :: SetForegroundWindow ( $_ . MainWindowHandle )
[WinAPI.ForegroundWindow] :: SetForegroundWindow ( $_ . MainWindowHandle )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Emulate the Backspace key sending
# Emulate the Backspace key sending
[System.Windows.Forms.SendKeys] :: SendWait ( " {BACKSPACE 1} " )
[System.Windows.Forms.SendKeys] :: SendWait ( " {BACKSPACE 1} " )
@ -5586,14 +5577,28 @@ function IPv6Component
$Enable
$Enable
)
)
# Check the internet connection
try
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 "
SslProtocol = " Tls13 "
DisableKeepAlive = $true
UseBasicParsing = $true
}
if ( -not ( Invoke-WebRequest @Parameters ) . StatusDescription )
{
{
return
}
# Check whether the ISP supports IPv6 protocol using https://ipv6-test.com
# 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 "
SslProtocol = " Tls13 "
UseBasicParsing = $true
}
}
$IPv6Test = Invoke-RestMethod @Parameters | Where-Object -FilterScript { $_ . proto -eq " ipv6 " }
}
}
catch [System.Net.WebException]
catch [System.Net.WebException]
{
{
@ -5601,8 +5606,6 @@ function IPv6Component
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
return
}
}
switch ( $PSCmdlet . ParameterSetName )
switch ( $PSCmdlet . ParameterSetName )
@ -6725,24 +6728,6 @@ function WinPrtScrFolder
Remove-ItemProperty -Path " HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders " -Name " {B7BEDE81-DF94-4682-A7D8-57A52620B86F} " -Force -ErrorAction Ignore
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
}
}
}
}
<#
<#
@ -8280,12 +8265,12 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Show window, if minimized
# Show window, if minimized
[WinAPI.ForegroundWindow] :: ShowWindowAsync ( $_ . MainWindowHandle , 10 )
[WinAPI.ForegroundWindow] :: ShowWindowAsync ( $_ . MainWindowHandle , 10 )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Force move the console window to the foreground
# Force move the console window to the foreground
[WinAPI.ForegroundWindow] :: SetForegroundWindow ( $_ . MainWindowHandle )
[WinAPI.ForegroundWindow] :: SetForegroundWindow ( $_ . MainWindowHandle )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Emulate the Backspace key sending
# Emulate the Backspace key sending
[System.Windows.Forms.SendKeys] :: SendWait ( " {BACKSPACE 1} " )
[System.Windows.Forms.SendKeys] :: SendWait ( " {BACKSPACE 1} " )
@ -9186,12 +9171,12 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Show window, if minimized
# Show window, if minimized
[WinAPI.ForegroundWindow] :: ShowWindowAsync ( $_ . MainWindowHandle , 10 )
[WinAPI.ForegroundWindow] :: ShowWindowAsync ( $_ . MainWindowHandle , 10 )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Force move the console window to the foreground
# Force move the console window to the foreground
[WinAPI.ForegroundWindow] :: SetForegroundWindow ( $_ . MainWindowHandle )
[WinAPI.ForegroundWindow] :: SetForegroundWindow ( $_ . MainWindowHandle )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Emulate the Backspace key sending to prevent the console window to freeze
# Emulate the Backspace key sending to prevent the console window to freeze
[System.Windows.Forms.SendKeys] :: SendWait ( " {BACKSPACE 1} " )
[System.Windows.Forms.SendKeys] :: SendWait ( " {BACKSPACE 1} " )
@ -9516,12 +9501,12 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Show window, if minimized
# Show window, if minimized
[WinAPI.ForegroundWindow] :: ShowWindowAsync ( $_ . MainWindowHandle , 10 )
[WinAPI.ForegroundWindow] :: ShowWindowAsync ( $_ . MainWindowHandle , 10 )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Force move the console window to the foreground
# Force move the console window to the foreground
[WinAPI.ForegroundWindow] :: SetForegroundWindow ( $_ . MainWindowHandle )
[WinAPI.ForegroundWindow] :: SetForegroundWindow ( $_ . MainWindowHandle )
Start-Sleep -Milliseconds 100
Start-Sleep -Seconds 1
# Emulate the Backspace key sending to prevent the console window to freeze
# Emulate the Backspace key sending to prevent the console window to freeze
[System.Windows.Forms.SendKeys] :: SendWait ( " {BACKSPACE 1} " )
[System.Windows.Forms.SendKeys] :: SendWait ( " {BACKSPACE 1} " )
@ -9596,24 +9581,48 @@ function HEIF
try
try
{
{
# Check the internet connection
# Check the internet connection
if ( ( Invoke-WebRequest -Uri https : / / www . google . com -UseBasicParsing -DisableKeepAlive -Method Head ) . StatusDescription )
$Parameters = @ {
Uri = " https://www.google.com "
Method = " Head "
SslProtocol = " Tls13 "
DisableKeepAlive = $true
UseBasicParsing = $true
}
if ( -not ( Invoke-WebRequest @Parameters ) . StatusDescription )
{
{
return
}
try
try
{
{
# Check whether the https://store.rg-adguard.net site is alive
# Check whether the https://store.rg-adguard.net site is alive
if ( ( Invoke-WebRequest -Uri https : / / store . rg-adguard . net / api / GetFiles -UseBasicParsing -DisableKeepAlive -Method Head ) . StatusDescription )
$Parameters = @ {
Uri = " https://store.rg-adguard.net/api/GetFiles "
Method = " Head "
SslProtocol = " Tls13 "
DisableKeepAlive = $true
UseBasicParsing = $true
}
if ( -not ( Invoke-RestMethod @Parameters ) . StatusDescription )
{
{
$API = " https://store.rg-adguard.net/api/GetFiles "
return
# HEVC Video Extensions from Device Manufacturer
}
$ProductURL = " https://www.microsoft.com/store/productId/9n4wgh0z6vhq "
$Body = @ {
$Parameters = @ {
Method = " Post "
Uri = " https://store.rg-adguard.net/api/GetFiles "
ContentType = " application/x-www-form-urlencoded "
Body = @ {
type = " url "
type = " url "
url = $ProductURL
# HEVC Video Extensions from Device Manufacturer
url = " https://www.microsoft.com/store/productId/9n4wgh0z6vhq "
ring = " Retail "
ring = " Retail "
lang = " en-US "
lang = " en-US "
}
}
$Raw = Invoke-RestMethod -Method Post -Uri $API -ContentType 'application/x-www-form-urlencoded' -Body $Body
UseBasicParsing = $true
SslProtocol = " Tls13 "
}
$Raw = Invoke-WebRequest @Parameters
# Parsing the page
# Parsing the page
$Raw | Select-String -Pattern '<tr style.*<a href=\"(?<url>.*)"\s.*>(?<text>.*)<\/a>' -AllMatches | ForEach-Object -Process { $_ . Matches } | ForEach-Object -Process {
$Raw | Select-String -Pattern '<tr style.*<a href=\"(?<url>.*)"\s.*>(?<text>.*)<\/a>' -AllMatches | ForEach-Object -Process { $_ . Matches } | ForEach-Object -Process {
@ -9629,7 +9638,8 @@ function HEIF
$Parameters = @ {
$Parameters = @ {
Uri = $TempURL
Uri = $TempURL
OutFile = " $ DownloadsFolder\ $ Package "
OutFile = " $ DownloadsFolder\ $ Package "
SslProtocol = " Tls12 "
SslProtocol = " Tls13 "
UseBasicParsing = $true
Verbose = $true
Verbose = $true
}
}
Invoke-WebRequest @Parameters
Invoke-WebRequest @Parameters
@ -9641,13 +9651,12 @@ function HEIF
}
}
}
}
}
}
}
catch [System.Net.WebException]
catch [System.Net.WebException]
{
{
Write-Warning -Message ( $Localization . NoResponse -f " https://store.rg-adguard.net " )
Write-Warning -Message ( $Localization . NoResponse -f " https://store.rg-adguard.net " )
Write-Error -Message ( $Localization . NoResponse -f " https://store.rg-adguard.net " ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . NoResponse -f " https://store.rg-adguard.net " ) -ErrorAction SilentlyContinue
return
}
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
}
}
}
}
catch [System.Net.WebException]
catch [System.Net.WebException]
@ -9656,8 +9665,6 @@ function HEIF
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
return
}
}
}
}
}
}
@ -9667,10 +9674,20 @@ function HEIF
{
{
try
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 "
SslProtocol = " Tls13 "
DisableKeepAlive = $true
UseBasicParsing = $true
}
if ( -not ( Invoke-WebRequest @Parameters ) . StatusDescription )
{
{
Start-Process -FilePath ms-windows -store : / / pdp / ? ProductId = 9n4wgh0z6vhq
return
}
}
Start-Process -FilePath ms-windows -store : / / pdp / ? ProductId = 9n4wgh0z6vhq
}
}
catch [System.Net.WebException]
catch [System.Net.WebException]
{
{
@ -9678,8 +9695,6 @@ function HEIF
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
return
}
}
}
}
}
}
@ -12089,10 +12104,23 @@ function BitmapImageNewContext
{
{
try
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 "
SslProtocol = " Tls13 "
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]
catch [System.Net.WebException]
{
{
@ -12100,8 +12128,6 @@ function BitmapImageNewContext
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
return
}
}
}
}
}
}
@ -12170,10 +12196,23 @@ function RichTextDocumentNewContext
{
{
try
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 "
SslProtocol = " Tls13 "
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]
catch [System.Net.WebException]
{
{
@ -12181,8 +12220,6 @@ function RichTextDocumentNewContext
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message $Localization . NoInternetConnection -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
Write-Error -Message ( $Localization . RestartFunction -f $MyInvocation . Line ) -ErrorAction SilentlyContinue
return
}
}
}
}
}
}
@ -12420,6 +12457,38 @@ public static void PostMessage()
Set-MpPreference -EnableControlledFolderAccess Enabled
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-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . RestartWarning
Write-Warning -Message $Localization . RestartWarning