diff --git a/Sophia/PowerShell 7/Functions.ps1 b/Sophia/PowerShell 7/Functions.ps1
index ea055cc2..aea50609 100644
--- a/Sophia/PowerShell 7/Functions.ps1
+++ b/Sophia/PowerShell 7/Functions.ps1
@@ -1,9 +1,9 @@
-<#
+<#
.SYNOPSIS
The TAB completion for functions and their arguments
- Version: v5.10.4
- Date: 07.05.2021
+ Version: v5.10.5
+ Date: 17.05.2021
Copyright (c) 2014–2021 farag
Copyright (c) 2019–2021 farag & oZ-Zo
@@ -66,7 +66,7 @@ function Sophia
Clear-Host
-$Host.UI.RawUI.WindowTitle = "Windows 10 Sophia Script v5.10.4 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows 10 | $([char]0x00A9) farag & oz-zo, 2014–2021"
+$Host.UI.RawUI.WindowTitle = "Windows 10 Sophia Script v5.10.5 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows 10 | $([char]0x00A9) farag & oz-zo, 2014–2021"
Remove-Module -Name Sophia -Force -ErrorAction Ignore
Import-Module -Name $PSScriptRoot\Sophia.psd1 -PassThru -Force
diff --git a/Sophia/PowerShell 7/Localizations/cn-CN/Sophia.psd1 b/Sophia/PowerShell 7/Localizations/cn-CN/Sophia.psd1
index 97abde5b..b909e9c2 100644
--- a/Sophia/PowerShell 7/Localizations/cn-CN/Sophia.psd1
+++ b/Sophia/PowerShell 7/Localizations/cn-CN/Sophia.psd1
@@ -1,4 +1,4 @@
-ConvertFrom-StringData -StringData @'
+ConvertFrom-StringData -StringData @'
UnsupportedOSBitness = 该脚本仅支持Windows 10 x64
UnsupportedOSBuild = 该脚本支持Windows 10版本2004/20H2/20H1和更高版本
UnsupportedRelease = 找到新版本
diff --git a/Sophia/PowerShell 7/Localizations/de-DE/Sophia.psd1 b/Sophia/PowerShell 7/Localizations/de-DE/Sophia.psd1
index 9c0c3ec1..23b8f819 100644
--- a/Sophia/PowerShell 7/Localizations/de-DE/Sophia.psd1
+++ b/Sophia/PowerShell 7/Localizations/de-DE/Sophia.psd1
@@ -1,4 +1,4 @@
-ConvertFrom-StringData -StringData @'
+ConvertFrom-StringData -StringData @'
UnsupportedOSBitness = Das Skript unterstützt nur Windows 10 x64
UnsupportedOSBuild = Das Skript unterstützt Windows 10 2004/20H2/20H1-Versionen und höher
UnsupportedRelease = Neue Version gefunden
diff --git a/Sophia/PowerShell 7/Localizations/en-US/Sophia.psd1 b/Sophia/PowerShell 7/Localizations/en-US/Sophia.psd1
index 5c562aa9..d906fc36 100644
--- a/Sophia/PowerShell 7/Localizations/en-US/Sophia.psd1
+++ b/Sophia/PowerShell 7/Localizations/en-US/Sophia.psd1
@@ -1,4 +1,4 @@
-ConvertFrom-StringData -StringData @'
+ConvertFrom-StringData -StringData @'
UnsupportedOSBitness = The script supports Windows 10 x64 only
UnsupportedOSBuild = The script supports Windows 10 2004/20H2/21H1 versions and higher
UnsupportedRelease = A new version found
diff --git a/Sophia/PowerShell 7/Localizations/es-ES/Sophia.psd1 b/Sophia/PowerShell 7/Localizations/es-ES/Sophia.psd1
index ebcde0ee..12c40c0b 100644
--- a/Sophia/PowerShell 7/Localizations/es-ES/Sophia.psd1
+++ b/Sophia/PowerShell 7/Localizations/es-ES/Sophia.psd1
@@ -1,4 +1,4 @@
-ConvertFrom-StringData -StringData @'
+ConvertFrom-StringData -StringData @'
UnsupportedOSBitness = El script sólo es compatible con Windows 10 x64
UnsupportedOSBuild = El script es compatible con versión Windows 10 2004/20H2/21H1 y superiores
UnsupportedRelease = Nueva versión encontrada
diff --git a/Sophia/PowerShell 7/Localizations/fr-FR/Sophia.psd1 b/Sophia/PowerShell 7/Localizations/fr-FR/Sophia.psd1
index 58617263..13db2298 100644
--- a/Sophia/PowerShell 7/Localizations/fr-FR/Sophia.psd1
+++ b/Sophia/PowerShell 7/Localizations/fr-FR/Sophia.psd1
@@ -1,4 +1,4 @@
-ConvertFrom-StringData -StringData @'
+ConvertFrom-StringData -StringData @'
UnsupportedOSBitness = Le script supporte uniquement Windows 10 x64
UnsupportedOSBuild = Le script supporte les versions Windows 10 2004/20H2/20H1 et ultérieures
UnsupportedRelease = Nouvelle version trouvée
diff --git a/Sophia/PowerShell 7/Localizations/it-IT/Sophia.psd1 b/Sophia/PowerShell 7/Localizations/it-IT/Sophia.psd1
index fdd47835..1d747a6f 100644
--- a/Sophia/PowerShell 7/Localizations/it-IT/Sophia.psd1
+++ b/Sophia/PowerShell 7/Localizations/it-IT/Sophia.psd1
@@ -1,4 +1,4 @@
-ConvertFrom-StringData -StringData @'
+ConvertFrom-StringData -StringData @'
UnsupportedOSBitness = Lo script supporta solo Windows 10 x64
UnsupportedOSBuild = Lo script supporta Windows 10, 2004/20H2/21H1 versioni e superiori
UnsupportedRelease = Nuova versione trovata
diff --git a/Sophia/PowerShell 7/Localizations/pt-BR/Sophia.psd1 b/Sophia/PowerShell 7/Localizations/pt-BR/Sophia.psd1
index dfef59be..70447bb9 100644
--- a/Sophia/PowerShell 7/Localizations/pt-BR/Sophia.psd1
+++ b/Sophia/PowerShell 7/Localizations/pt-BR/Sophia.psd1
@@ -1,4 +1,4 @@
-ConvertFrom-StringData -StringData @'
+ConvertFrom-StringData -StringData @'
UnsupportedOSBitness = O script suporta somente Windows 10 x64
UnsupportedOSBuild = O script suporta versões Windows 10 2004/20H2/21H1 e superior
UnsupportedRelease = Nova versão encontrada
diff --git a/Sophia/PowerShell 7/Localizations/tr-TR/Sophia.psd1 b/Sophia/PowerShell 7/Localizations/tr-TR/Sophia.psd1
index 2f56bdb9..847a0e0f 100644
--- a/Sophia/PowerShell 7/Localizations/tr-TR/Sophia.psd1
+++ b/Sophia/PowerShell 7/Localizations/tr-TR/Sophia.psd1
@@ -1,4 +1,4 @@
-ConvertFrom-StringData -StringData @'
+ConvertFrom-StringData -StringData @'
UnsupportedOSBitness = Bu betik sadece Windows 10 x64 destekliyor
UnsupportedOSBuild = Bu betik sadece Windows 10 2004/20H2/21H1 sürüm ve üstünü destekliyor
UnsupportedRelease = Yeni sürüm bulundu
diff --git a/Sophia/PowerShell 7/Sophia.ps1 b/Sophia/PowerShell 7/Sophia.ps1
index e3452cef..80b34734 100644
--- a/Sophia/PowerShell 7/Sophia.ps1
+++ b/Sophia/PowerShell 7/Sophia.ps1
@@ -1,9 +1,9 @@
-<#
+<#
.SYNOPSIS
Default preset file for "Windows 10 Sophia Script"
- Version: v5.10.4
- Date: 07.05.2021
+ Version: v5.10.5
+ Date: 17.05.2021
Copyright (c) 2014–2021 farag
Copyright (c) 2019–2021 farag & oZ-Zo
@@ -71,7 +71,7 @@ param
Clear-Host
-$Host.UI.RawUI.WindowTitle = "Windows 10 Sophia Script v5.10.4 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows 10 | $([char]0x00A9) farag & oz-zo, 2014–2021"
+$Host.UI.RawUI.WindowTitle = "Windows 10 Sophia Script v5.10.5 | Made with $([char]::ConvertFromUtf32(0x1F497)) of Windows 10 | $([char]0x00A9) farag & oz-zo, 2014–2021"
Remove-Module -Name Sophia -Force -ErrorAction Ignore
Import-Module -Name $PSScriptRoot\Sophia.psd1 -PassThru -Force
@@ -107,10 +107,10 @@ if ($Functions)
#region Protection
<#
- Checkings. If you want disable a warning message about whether you've customized the preset file remove the Warning argument
+ Checkings. If you want to disable a warning message about whether you've customized the preset file remove the "-Warning" argument
Please, do not comment out this function
- Проверки
+ Проверки. Чтобы выключить предупреждение о необходимости настройки пресет-файла, удалите аргумент "-Warning"
Пожалуйста, не комментируйте данную функцию
#>
Checkings -Warning
diff --git a/Sophia/PowerShell 7/Sophia.psd1 b/Sophia/PowerShell 7/Sophia.psd1
index 94478ba9..78744d09 100644
--- a/Sophia/PowerShell 7/Sophia.psd1
+++ b/Sophia/PowerShell 7/Sophia.psd1
@@ -1,6 +1,6 @@
-@{
+@{
RootModule = 'Sophia.psm1'
- ModuleVersion = '5.10.4'
+ ModuleVersion = '5.10.5'
GUID = 'aa0b47a7-1770-4b5d-8c9f-cc6c505bcc7a'
Author = 'Dmitry "farag" Nefedov'
Copyright = '(c) 2014–2021 farag & oZ-Zo. All rights reserved.'
diff --git a/Sophia/PowerShell 7/Sophia.psm1 b/Sophia/PowerShell 7/Sophia.psm1
index d98a9613..b7e244b8 100644
--- a/Sophia/PowerShell 7/Sophia.psm1
+++ b/Sophia/PowerShell 7/Sophia.psm1
@@ -2,8 +2,8 @@
.SYNOPSIS
"Windows 10 Sophia Script" is a PowerShell module for Windows 10 fine-tuning and automating the routine tasks
- Version: v5.10.4
- Date: 07.05.2021
+ Version: v5.10.5
+ Date: 17.05.2021
Copyright (c) 2014–2021 farag
Copyright (c) 2019–2021 farag & oZ-Zo
@@ -545,10 +545,11 @@ function ScheduledTasks
MinHeight="450" MinWidth="400"
SizeToContent="Width" WindowStartupLocation="CenterScreen"
TextOptions.TextFormattingMode="Display" SnapsToDevicePixels="True"
- FontFamily="Segoe UI" FontSize="12" ShowInTaskbar="False">
+ FontFamily="Candara" FontSize="16" ShowInTaskbar="True">
+
+
+
@@ -572,7 +585,7 @@ function ScheduledTasks
VerticalScrollBarVisibility="Auto">
-
+
'
@@ -708,11 +721,55 @@ function ScheduledTasks
Write-Verbose -Message $Localization.DialogBoxOpening -Verbose
+ #region Sendkey function
+ # Emulate the Backspace key sending to prevent the console window to freeze
+ Start-Sleep -Milliseconds 500
+
+ Add-Type -AssemblyName System.Windows.Forms
+
+ $SetForegroundWindow = @{
+ Namespace = "WinAPI"
+ Name = "ForegroundWindow"
+ Language = "CSharp"
+ MemberDefinition = @"
+[DllImport("user32.dll")]
+public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
+
+[DllImport("user32.dll")]
+[return: MarshalAs(UnmanagedType.Bool)]
+public static extern bool SetForegroundWindow(IntPtr hWnd);
+"@
+ }
+
+ if (-not ("WinAPI.ForegroundWindow" -as [type]))
+ {
+ Add-Type @SetForegroundWindow
+ }
+
+ Get-Process | Where-Object -FilterScript {$_.MainWindowTitle -like "Windows 10 Sophia Script*"} | ForEach-Object -Process {
+ # Show window, if minimized
+ [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10)
+
+ Start-Sleep -Milliseconds 100
+
+ # Force move the console window to the foreground
+ [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle)
+
+ Start-Sleep -Milliseconds 100
+
+ # Emulate the Backspace key sending
+ [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}")
+ }
+ #endregion Sendkey function
+
$Window.Add_Loaded({$Tasks | Add-TaskControl})
$Button.Content = $ButtonContent
$Button.Add_Click({& $ButtonAdd_Click})
$Window.Title = $Localization.ScheduledTasks
+
+ # Force move the WPF form to the foreground
+ $Window.Add_Loaded({$Window.Activate()})
$Form.ShowDialog() | Out-Null
}
@@ -2568,8 +2625,10 @@ function UnpinTaskbarEdgeStore
MemberDefinition = @"
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetModuleHandle(string lpModuleName);
+
[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern int LoadString(IntPtr hInstance, uint uID, StringBuilder lpBuffer, int nBufferMax);
+
public static string GetString(uint strId)
{
IntPtr intPtr = GetModuleHandle("shell32.dll");
@@ -4459,10 +4518,11 @@ function WindowsFeatures
MinHeight="450" MinWidth="400"
SizeToContent="Width" WindowStartupLocation="CenterScreen"
TextOptions.TextFormattingMode="Display" SnapsToDevicePixels="True"
- FontFamily="Segoe UI" FontSize="12" ShowInTaskbar="False">
+ FontFamily="Candara" FontSize="16" ShowInTaskbar="True">
+
+
+
@@ -4486,7 +4558,7 @@ function WindowsFeatures
VerticalScrollBarVisibility="Auto">
-
+
'
@@ -4630,11 +4702,55 @@ function WindowsFeatures
Write-Verbose -Message $Localization.DialogBoxOpening -Verbose
+ #region Sendkey function
+ # Emulate the Backspace key sending to prevent the console window to freeze
+ Start-Sleep -Milliseconds 500
+
+ Add-Type -AssemblyName System.Windows.Forms
+
+ $SetForegroundWindow = @{
+ Namespace = "WinAPI"
+ Name = "ForegroundWindow"
+ Language = "CSharp"
+ MemberDefinition = @"
+[DllImport("user32.dll")]
+public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
+
+[DllImport("user32.dll")]
+[return: MarshalAs(UnmanagedType.Bool)]
+public static extern bool SetForegroundWindow(IntPtr hWnd);
+"@
+ }
+
+ if (-not ("WinAPI.ForegroundWindow" -as [type]))
+ {
+ Add-Type @SetForegroundWindow
+ }
+
+ Get-Process | Where-Object -FilterScript {$_.MainWindowTitle -like "Windows 10 Sophia Script*"} | ForEach-Object -Process {
+ # Show window, if minimized
+ [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10)
+
+ Start-Sleep -Milliseconds 100
+
+ # Force move the console window to the foreground
+ [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle)
+
+ Start-Sleep -Milliseconds 100
+
+ # Emulate the Backspace key sending
+ [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}")
+ }
+ #endregion Sendkey function
+
$Window.Add_Loaded({$Features | Add-FeatureControl})
$Button.Content = $ButtonContent
$Button.Add_Click({& $ButtonAdd_Click})
$Window.Title = $Localization.WindowsFeaturesTitle
+
+ # Force move the WPF form to the foreground
+ $Window.Add_Loaded({$Window.Activate()})
$Form.ShowDialog() | Out-Null
}
@@ -4765,10 +4881,11 @@ function WindowsCapabilities
MinHeight="450" MinWidth="400"
SizeToContent="Width" WindowStartupLocation="CenterScreen"
TextOptions.TextFormattingMode="Display" SnapsToDevicePixels="True"
- FontFamily="Segoe UI" FontSize="12" ShowInTaskbar="False">
+ FontFamily="Candara" FontSize="16" ShowInTaskbar="True">
+
+
+
@@ -4792,7 +4921,7 @@ function WindowsCapabilities
VerticalScrollBarVisibility="Auto">
-
+
'
@@ -4960,11 +5089,55 @@ function WindowsCapabilities
Write-Verbose -Message $Localization.DialogBoxOpening -Verbose
+ #region Sendkey function
+ # Emulate the Backspace key sending to prevent the console window to freeze
+ Start-Sleep -Milliseconds 500
+
+ Add-Type -AssemblyName System.Windows.Forms
+
+ $SetForegroundWindow = @{
+ Namespace = "WinAPI"
+ Name = "ForegroundWindow"
+ Language = "CSharp"
+ MemberDefinition = @"
+[DllImport("user32.dll")]
+public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
+
+[DllImport("user32.dll")]
+[return: MarshalAs(UnmanagedType.Bool)]
+public static extern bool SetForegroundWindow(IntPtr hWnd);
+"@
+ }
+
+ if (-not ("WinAPI.ForegroundWindow" -as [type]))
+ {
+ Add-Type @SetForegroundWindow
+ }
+
+ Get-Process | Where-Object -FilterScript {$_.MainWindowTitle -like "Windows 10 Sophia Script*"} | ForEach-Object -Process {
+ # Show window, if minimized
+ [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10)
+
+ Start-Sleep -Milliseconds 100
+
+ # Force move the console window to the foreground
+ [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle)
+
+ Start-Sleep -Milliseconds 100
+
+ # Emulate the Backspace key sending
+ [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}")
+ }
+ #endregion Sendkey function
+
$Window.Add_Loaded({$Capabilities | Add-CapabilityControl})
$Button.Content = $ButtonContent
$Button.Add_Click({& $ButtonAdd_Click})
$Window.Title = $Localization.OptionalFeaturesTitle
+
+ # Force move the WPF form to the foreground
+ $Window.Add_Loaded({$Window.Activate()})
$Form.ShowDialog() | Out-Null
}
@@ -5549,8 +5722,10 @@ public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, Int
MemberDefinition = @"
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetModuleHandle(string lpModuleName);
+
[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern int LoadString(IntPtr hInstance, uint uID, StringBuilder lpBuffer, int nBufferMax);
+
public static string GetString(uint strId)
{
IntPtr intPtr = GetModuleHandle("shell32.dll");
@@ -5763,7 +5938,7 @@ public static string GetString(uint strId)
$FolderBrowserDialog.Description = $Localization.FolderSelect
$FolderBrowserDialog.RootFolder = "MyComputer"
- # Focus on open file dialog
+ # Force move the open file dialog to the foreground
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$FolderBrowserDialog.ShowDialog($Focus)
@@ -5799,7 +5974,7 @@ public static string GetString(uint strId)
$FolderBrowserDialog.Description = $Localization.FolderSelect
$FolderBrowserDialog.RootFolder = "MyComputer"
- # Focus on open file dialog
+ # Force move the open file dialog to the foreground
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$FolderBrowserDialog.ShowDialog($Focus)
@@ -5835,7 +6010,7 @@ public static string GetString(uint strId)
$FolderBrowserDialog.Description = $Localization.FolderSelect
$FolderBrowserDialog.RootFolder = "MyComputer"
- # Focus on open file dialog
+ # Force move the open file dialog to the foreground
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$FolderBrowserDialog.ShowDialog($Focus)
@@ -5871,7 +6046,7 @@ public static string GetString(uint strId)
$FolderBrowserDialog.Description = $Localization.FolderSelect
$FolderBrowserDialog.RootFolder = "MyComputer"
- # Focus on open file dialog
+ # Force move the open file dialog to the foreground
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$FolderBrowserDialog.ShowDialog($Focus)
@@ -5907,7 +6082,7 @@ public static string GetString(uint strId)
$FolderBrowserDialog.Description = $Localization.FolderSelect
$FolderBrowserDialog.RootFolder = "MyComputer"
- # Focus on open file dialog
+ # Force move the open file dialog to the foreground
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$FolderBrowserDialog.ShowDialog($Focus)
@@ -5943,7 +6118,7 @@ public static string GetString(uint strId)
$FolderBrowserDialog.Description = $Localization.FolderSelect
$FolderBrowserDialog.RootFolder = "MyComputer"
- # Focus on open file dialog
+ # Force move the open file dialog to the foreground
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$FolderBrowserDialog.ShowDialog($Focus)
@@ -7882,8 +8057,10 @@ function PinToStart
MemberDefinition = @"
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetModuleHandle(string lpModuleName);
+
[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern int LoadString(IntPtr hInstance, uint uID, StringBuilder lpBuffer, int nBufferMax);
+
public static string GetString(uint strId)
{
IntPtr intPtr = GetModuleHandle("shell32.dll");
@@ -8492,10 +8669,52 @@ function UninstallUWPApps
{
Write-Verbose -Message $Localization.DialogBoxOpening -Verbose
+ #region Sendkey function
+ # Emulate the Backspace key sending to prevent the console window to freeze
+ Start-Sleep -Milliseconds 500
+
+ Add-Type -AssemblyName System.Windows.Forms
+
+ $SetForegroundWindow = @{
+ Namespace = "WinAPI"
+ Name = "ForegroundWindow"
+ Language = "CSharp"
+ MemberDefinition = @"
+[DllImport("user32.dll")]
+public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
+
+[DllImport("user32.dll")]
+[return: MarshalAs(UnmanagedType.Bool)]
+public static extern bool SetForegroundWindow(IntPtr hWnd);
+"@
+ }
+
+ if (-not ("WinAPI.ForegroundWindow" -as [type]))
+ {
+ Add-Type @SetForegroundWindow
+ }
+
+ Get-Process | Where-Object -FilterScript {$_.MainWindowTitle -like "Windows 10 Sophia Script*"} | ForEach-Object -Process {
+ # Show window, if minimized
+ [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10)
+
+ Start-Sleep -Milliseconds 100
+
+ # Force move the console window to the foreground
+ [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle)
+
+ Start-Sleep -Milliseconds 100
+
+ # Emulate the Backspace key sending to prevent the console window to freeze
+ [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}")
+ }
+ #endregion Sendkey function
+
if ($PackagesToRemove.Count -gt 0)
{
$ButtonUninstall.IsEnabled = $true
}
+
$Form.ShowDialog() | Out-Null
}
}
@@ -8617,7 +8836,7 @@ function RestoreUWPApps
{
Write-Verbose -Message $Localization.Patient -Verbose
- # Тут нельзя напрямую вписать -PackageTypeFilter Bundle, так как иначе не выдается нужное свойство InstallLocation. Только сравнивать с $Bundles
+ # You cannot retrieve packages using -PackageTypeFilter Bundle, otherwise you won't get the InstallLocation attribute. It can be retrieved only by comparing with $Bundles
$Bundles = (Get-AppXPackage -PackageTypeFilter Bundle -AllUsers).Name
$AppxPackages = Get-AppxPackage -AllUsers | Where-Object -FilterScript {$_.PackageUserInformation -match "Staged"} | Where-Object -FilterScript {$_.Name -in $Bundles}
$PackagesIds = [Windows.Management.Deployment.PackageManager]::new().FindPackages().AdditionalTypeData[[Collections.IEnumerable].TypeHandle] | Select-Object -Property DisplayName -ExpandProperty Id | Select-Object -Property Name, DisplayName
@@ -8776,10 +8995,52 @@ function RestoreUWPApps
{
Write-Verbose -Message $Localization.DialogBoxOpening -Verbose
+ # Emulate the Backspace key sending to prevent the console window to freeze
+ Start-Sleep -Milliseconds 500
+
+ Add-Type -AssemblyName System.Windows.Forms
+
+ $SetForegroundWindow = @{
+ Namespace = "WinAPI"
+ Name = "ForegroundWindow"
+ Language = "CSharp"
+ MemberDefinition = @"
+[DllImport("user32.dll")]
+public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
+
+[DllImport("user32.dll")]
+[return: MarshalAs(UnmanagedType.Bool)]
+public static extern bool SetForegroundWindow(IntPtr hWnd);
+"@
+ }
+
+ if (-not ("WinAPI.ForegroundWindow" -as [type]))
+ {
+ Add-Type @SetForegroundWindow
+ }
+
+ Get-Process | Where-Object -FilterScript {$_.MainWindowTitle -like "Windows 10 Sophia Script*"} | ForEach-Object -Process {
+ # Show window, if minimized
+ [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10)
+
+ Start-Sleep -Milliseconds 100
+
+ # Force move the console window to the foreground
+ [WinAPI.ForegroundWindow]::SetForegroundWindow($_.MainWindowHandle)
+
+ Start-Sleep -Milliseconds 100
+
+ # Emulate the Backspace key sending to prevent the console window to freeze
+ [System.Windows.Forms.SendKeys]::SendWait("{BACKSPACE 1}")
+ }
+
if ($PackagesToRestore.Count -gt 0)
{
$ButtonRestore.IsEnabled = $true
}
+
+ # Force move the WPF form to the foreground
+ $Window.Add_Loaded({$Window.Activate()})
$Form.ShowDialog() | Out-Null
}
}
@@ -9233,7 +9494,7 @@ function SetAppGraphicsPerformance
$OpenFileDialog.InitialDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
$OpenFileDialog.Multiselect = $false
- # Focus on open file dialog
+ # Force move the open file dialog to the foreground
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$OpenFileDialog.ShowDialog($Focus)
@@ -9498,19 +9759,16 @@ while (`$true)
}
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel" -Name ShowInActionCenter -PropertyType DWord -Value 1 -Force
- # Register the "WindowsCleanup" protocol to be able to run the scheduled task upon clicking on the "Run" button
- if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup))
+ # Register the "WindowsCleanup" protocol to be able to run the scheduled task by clicking the "Run" button in a toast
+ if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command))
{
- New-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Force
+ New-Item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Force
}
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "(default)" -PropertyType String -Value "URL:WindowsCleanup" -Force
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name "URL Protocol" -Value "" -Force
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup -Name EditFlags -PropertyType DWord -Value 2162688 -Force
- if (-not (Test-Path -Path Registry::HKEY_CLASSES_ROOT\shell\open\command))
- {
- New-item -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Force
- }
- # If "Run" clicked run the "Windows Cleanup" task
+
+ # Start the "Windows Cleanup" task if the "Run" button clicked
New-ItemProperty -Path Registry::HKEY_CLASSES_ROOT\WindowsCleanup\shell\open\command -Name "(default)" -PropertyType String -Value 'powershell.exe -Command "& {Start-ScheduledTask -TaskPath ''\Sophia Script\'' -TaskName ''Windows Cleanup''}"' -Force
$ToastNotification = @"
@@ -9810,7 +10068,7 @@ function AddProtectedFolders
$FolderBrowserDialog.Description = $Localization.FolderSelect
$FolderBrowserDialog.RootFolder = "MyComputer"
- # Focus on open file dialog
+ # Force move the open file dialog to the foreground
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$FolderBrowserDialog.ShowDialog($Focus)
@@ -9864,7 +10122,7 @@ function AddAppControlledFolder
$OpenFileDialog.InitialDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
$OpenFileDialog.Multiselect = $false
- # Focus on open file dialog
+ # Force move the open file dialog to the foreground
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$OpenFileDialog.ShowDialog($Focus)
@@ -9916,7 +10174,7 @@ function AddDefenderExclusionFolder
$FolderBrowserDialog.Description = $Localization.FolderSelect
$FolderBrowserDialog.RootFolder = "MyComputer"
- # Focus on open file dialog
+ # Force move the open file dialog to the foreground
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$FolderBrowserDialog.ShowDialog($Focus)
@@ -9970,7 +10228,7 @@ function AddDefenderExclusionFile
$OpenFileDialog.InitialDirectory = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
$OpenFileDialog.Multiselect = $false
- # Focus on open file dialog
+ # Force move the open file dialog to the foreground
$Focus = New-Object -TypeName System.Windows.Forms.Form -Property @{TopMost = $true}
$OpenFileDialog.ShowDialog($Focus)
@@ -11840,12 +12098,15 @@ private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff);
private const int WM_SETTINGCHANGE = 0x1a;
private const int SMTO_ABORTIFHUNG = 0x0002;
-[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
-static extern bool SendNotifyMessage(IntPtr hWnd, uint Msg, IntPtr wParam, string lParam);
-[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
-private static extern IntPtr SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, string lParam, int fuFlags, int uTimeout, IntPtr lpdwResult);
[DllImport("shell32.dll", CharSet = CharSet.Auto, SetLastError = false)]
private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);
+
+[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
+private static extern IntPtr SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, string lParam, int fuFlags, int uTimeout, IntPtr lpdwResult);
+
+[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
+static extern bool SendNotifyMessage(IntPtr hWnd, uint Msg, IntPtr wParam, string lParam);
+
public static void Refresh()
{
// Update desktop icons
@@ -11865,6 +12126,7 @@ private static readonly UIntPtr UIntPtr = new UIntPtr(41504);
[DllImport("user32.dll", SetLastError=true)]
public static extern int PostMessageW(IntPtr hWnd, uint Msg, UIntPtr wParam, IntPtr lParam);
+
public static void PostMessage()
{
// Simulate pressing F5 to refresh the desktop