Browse Source

Updated Wrapper, improved post actions

pull/450/head
Dmitry Nefedov 2 years ago
parent
commit
63f7b2c07a
  1. 22
      Wrapper/Config/before_after.json
  2. BIN
      Wrapper/SophiaScriptWrapper.exe
  3. 21
      src/Sophia_Script_for_Windows_10/Module/Sophia.psm1
  4. 2
      src/Sophia_Script_for_Windows_10/Sophia.ps1
  5. 12
      src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1
  6. 2
      src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1
  7. 193
      src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1
  8. 2
      src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1
  9. 21
      src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1
  10. 2
      src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1
  11. 25
      src/Sophia_Script_for_Windows_11/Module/Sophia.psm1
  12. 33
      src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1
  13. 2
      src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1

22
Wrapper/Config/before_after.json

@ -0,0 +1,22 @@
[
{
"Id": 100,
"Region": "before",
"Function": "",
},
{
"Id": 101,
"Region": "before",
"Function": "",
},
{
"Id": 200,
"Region": "after",
"Function": "PostActions",
},
{
"Id": 201,
"Region": "after",
"Function": "Errors",
}
]

BIN
Wrapper/SophiaScriptWrapper.exe

Binary file not shown.

21
src/Sophia_Script_for_Windows_10/Module/Sophia.psm1

@ -4442,16 +4442,10 @@ function OneDrive
return return
} }
# Check if script was launched from OneDrive folder and preset file has function to uninstall OneDrive
# Check how the script was invoked: via a preset or Function.ps1
$PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript {
(($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and ($_.Text -eq "OneDrive -Uninstall") -or ($_.Text -match "Invoke-Expression")
}
# Check if user is logged into OneDrive account (Microsoft account) # Check if user is logged into OneDrive account (Microsoft account)
$UserEmail = Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Personal -Name UserEmail -ErrorAction Ignore $UserEmail = Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Personal -Name UserEmail -ErrorAction Ignore
if ($PresetName -and $UserEmail) if ($UserEmail)
{ {
# Exit if user accidentally set function in preset to uninstall but he's logged into the app
return return
} }
@ -7706,6 +7700,7 @@ function WinPrtScrFolder
$PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript { $PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript {
(($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and (($_.Text -eq "WinPrtScrFolder -Desktop") -or ($_.Text -match "Invoke-Expression")) (($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and (($_.Text -eq "WinPrtScrFolder -Desktop") -or ($_.Text -match "Invoke-Expression"))
} }
if ($PresetName) if ($PresetName)
{ {
# Get the name of a preset (e.g Sophia.ps1) regardless it was named # Get the name of a preset (e.g Sophia.ps1) regardless it was named
@ -11844,6 +11839,8 @@ public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
Description = $Localization.CleanupNotificationTaskDescription Description = $Localization.CleanupNotificationTaskDescription
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -12027,6 +12024,8 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For
Description = $Localization.FolderTaskDescription -f "%SystemRoot%\SoftwareDistribution\Download" Description = $Localization.FolderTaskDescription -f "%SystemRoot%\SoftwareDistribution\Download"
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -12205,6 +12204,8 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_
Description = $Localization.FolderTaskDescription -f "%TEMP%" Description = $Localization.FolderTaskDescription -f "%TEMP%"
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -14287,11 +14288,7 @@ public static void PostMessage()
} }
# Check if any of scheduled tasks were created. Unless open Task Scheduler # Check if any of scheduled tasks were created. Unless open Task Scheduler
# Check how the script was invoked: via a preset or Function.ps1 if ($Script:ScheduledTasks)
$PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript {
(($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and (($_.Text -eq "CleanupTask -Register") -or ($_.Text -eq "CleanupTask -Register") -or ($_.Text -eq "TempTask -Register")) -or ($_.Text -match "Invoke-Expression")
}
if ($PresetName)
{ {
# Open Task Scheduler # Open Task Scheduler
Start-Process -FilePath taskschd.msc Start-Process -FilePath taskschd.msc

2
src/Sophia_Script_for_Windows_10/Sophia.ps1

@ -979,7 +979,7 @@ InstallVCRedist
<# <#
Install the latest .NET Desktop Runtime 6, 7 (x86/x64) Install the latest .NET Desktop Runtime 6, 7 (x86/x64)
Установить последнюю версию .NET Desktop Runtime 6 (x86/x64) Установить последнюю версию .NET Desktop Runtime 6, 7 (x86/x64)
https://dotnet.microsoft.com/en-us/download/dotnet https://dotnet.microsoft.com/en-us/download/dotnet
#> #>

12
src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1

@ -8486,6 +8486,8 @@ public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
Description = $Localization.CleanupNotificationTaskDescription Description = $Localization.CleanupNotificationTaskDescription
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -8669,6 +8671,8 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For
Description = $Localization.FolderTaskDescription -f "%SystemRoot%\SoftwareDistribution\Download" Description = $Localization.FolderTaskDescription -f "%SystemRoot%\SoftwareDistribution\Download"
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -8847,6 +8851,8 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_
Description = $Localization.FolderTaskDescription -f "%TEMP%" Description = $Localization.FolderTaskDescription -f "%TEMP%"
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -10707,11 +10713,7 @@ public static void PostMessage()
} }
# Check if any of scheduled tasks were created. Unless open Task Scheduler # Check if any of scheduled tasks were created. Unless open Task Scheduler
# Check how the script was invoked: via a preset or Function.ps1 if ($Script:ScheduledTasks)
$PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript {
(($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and (($_.Text -eq "CleanupTask -Register") -or ($_.Text -eq "CleanupTask -Register") -or ($_.Text -eq "TempTask -Register")) -or ($_.Text -match "Invoke-Expression")
}
if ($PresetName)
{ {
# Open Task Scheduler # Open Task Scheduler
Start-Process -FilePath taskschd.msc Start-Process -FilePath taskschd.msc

2
src/Sophia_Script_for_Windows_10_LTSC_2019/Sophia.ps1

@ -780,7 +780,7 @@ InstallVCRedist
<# <#
Install the latest .NET Desktop Runtime 6, 7 (x86/x64) Install the latest .NET Desktop Runtime 6, 7 (x86/x64)
Установить последнюю версию .NET Desktop Runtime 6 (x86/x64) Установить последнюю версию .NET Desktop Runtime 6, 7 (x86/x64)
https://dotnet.microsoft.com/en-us/download/dotnet https://dotnet.microsoft.com/en-us/download/dotnet
#> #>

193
src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1

@ -8297,7 +8297,13 @@ function InstallVCRedist
Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait
# PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word # PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word
Get-ChildItem -Path "$DownloadsFolder\VC_redist.x86.exe", "$DownloadsFolder\VC_redist.x64.exe", "$env:TEMP\dd_vcredist_amdx86_*.log", "$env:TEMP\dd_vcredist_amd64_*.log" -Force | Remove-Item -Recurse -Force -ErrorAction Ignore $Paths = @(
"$DownloadsFolder\VC_redist.x86.exe",
"$DownloadsFolder\VC_redist.x64.exe",
"$env:TEMP\dd_vcredist_x86_*.log",
"$env:TEMP\dd_vcredist_amd64_*.log"
)
Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore
} }
catch [System.Net.WebException] catch [System.Net.WebException]
{ {
@ -8321,7 +8327,7 @@ function InstallVCRedist
.NOTES .NOTES
Machine-wide Machine-wide
#> #>
function InstallVCRedist function InstallDotNetRuntimes
{ {
try try
{ {
@ -8339,41 +8345,95 @@ function InstallVCRedist
if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17") if ([System.Version](Get-AppxPackage -Name Microsoft.DesktopAppInstaller -ErrorAction Ignore).Version -ge [System.Version]"1.17")
{ {
winget install --id=Microsoft.VCRedist.2015+.x86 --exact --accept-source-agreements # .NET Desktop Runtime 6 x86
winget install --id=Microsoft.VCRedist.2015+.x64 --exact --accept-source-agreements winget install --id=Microsoft.DotNet.DesktopRuntime.6 --architecture x86 --exact --accept-source-agreements
# .NET Desktop Runtime 7 x64
winget install --id=Microsoft.DotNet.DesktopRuntime.6 --architecture x64 --exact --accept-source-agreements
# .NET Desktop Runtime 7 x86
winget install --id=Microsoft.DotNet.DesktopRuntime.7 --architecture x86 --exact --accept-source-agreements
# .NET Desktop Runtime 7 x64
winget install --id=Microsoft.DotNet.DesktopRuntime.7 --architecture x64 --exact --accept-source-agreements
} }
else else
{ {
# Install .NET Desktop Runtime 6
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
$Parameters = @{
Uri = "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/6.0/releases.json"
UseBasicParsing = $true
}
$LatestRelease = (Invoke-RestMethod @Parameters)."latest-release"
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}" $DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
# .NET Desktop Runtime 6 x86
$Parameters = @{ $Parameters = @{
Uri = "https://aka.ms/vs/17/release/VC_redist.x86.exe" Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x86.exe"
OutFile = "$DownloadsFolder\VC_redist.x86.exe" OutFile = "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x86.exe"
UseBasicParsing = $true UseBasicParsing = $true
Verbose = $true Verbose = $true
} }
Invoke-WebRequest @Parameters Invoke-WebRequest @Parameters
Start-Process -FilePath "$DownloadsFolder\VC_redist.x86.exe" -ArgumentList "/install /passive /norestart" -Wait Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x86.exe" -ArgumentList "/install /passive /norestart" -Wait
# .NET Desktop Runtime 6 x64
$Parameters = @{ $Parameters = @{
Uri = "https://aka.ms/vs/17/release/VC_redist.x64.exe" Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe"
OutFile = "$DownloadsFolder\VC_redist.x64.exe" OutFile = "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe"
UseBasicParsing = $true UseBasicParsing = $true
Verbose = $true Verbose = $true
} }
Invoke-WebRequest @Parameters Invoke-WebRequest @Parameters
Start-Process -FilePath "$DownloadsFolder\VC_redist.x64.exe" -ArgumentList "/install /passive /norestart" -Wait Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait
# PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word # PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word
$Paths = @( $Paths = @(
"$DownloadsFolder\VC_redist.x86.exe", "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x86.exe",
"$DownloadsFolder\VC_redist.x64.exe", "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe",
"$env:TEMP\dd_vcredist_x86_*.log", "$env:TEMP\Microsoft_.NET_Runtime*.log"
"$env:TEMP\dd_vcredist_amd64_*.log",
"$env:TEMP\WinGet"
) )
Get-ChildItem -Path $Paths -Recurse -Force | Remove-Item -Recurse -Force -ErrorAction Ignore Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
# .NET Desktop Runtime 7
# https://github.com/dotnet/core/blob/main/release-notes/releases-index.json
$Parameters = @{
Uri = "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/7.0/releases.json"
UseBasicParsing = $true
}
$LatestRelease = (Invoke-RestMethod @Parameters)."latest-release"
$DownloadsFolder = Get-ItemPropertyValue -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{374DE290-123F-4565-9164-39C4925E467B}"
# .NET Desktop Runtime 7 x86
$Parameters = @{
Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x86.exe"
OutFile = "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x86.exe"
UseBasicParsing = $true
Verbose = $true
}
Invoke-WebRequest @Parameters
Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x86.exe" -ArgumentList "/install /passive /norestart" -Wait
# .NET Desktop Runtime 7 x64
$Parameters = @{
Uri = "https://dotnetcli.azureedge.net/dotnet/Runtime/$LatestRelease/dotnet-runtime-$LatestRelease-win-x64.exe"
OutFile = "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe"
UseBasicParsing = $true
Verbose = $true
}
Invoke-WebRequest @Parameters
Start-Process -FilePath "$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe" -ArgumentList "/install /passive /norestart" -Wait
# PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word
$Paths = @(
"$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x86.exe",
"$DownloadsFolder\dotnet-runtime-$LatestRelease-win-x64.exe",
"$env:TEMP\Microsoft_.NET_Runtime*.log"
)
Get-ChildItem -Path $Paths -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
} }
} }
catch [System.Net.WebException] catch [System.Net.WebException]
@ -8559,7 +8619,7 @@ function PreventEdgeShortcutCreation
.SYNOPSIS .SYNOPSIS
Windows Subsystem for Linux (WSL) Windows Subsystem for Linux (WSL)
.PARAMETER Install .PARAMETER
Enable Windows Subsystem for Linux (WSL), install the latest WSL Linux kernel version, and a Linux distribution using a pop-up form Enable Windows Subsystem for Linux (WSL), install the latest WSL Linux kernel version, and a Linux distribution using a pop-up form
.EXAMPLE .EXAMPLE
@ -8573,6 +8633,15 @@ function PreventEdgeShortcutCreation
#> #>
function Install-WSL function Install-WSL
{ {
[System.Console]::OutputEncoding = [System.Text.Encoding]::Unicode
$Distros = (wsl --list --online | Select-Object -Skip 8).Replace(" ", "").Replace("* ", "") | ForEach-Object -Process {
[PSCustomObject]@{
"Distro" = $_ -split " ", 2 | Select-Object -Last 1
"Alias" = $_ -split " ", 2 | Select-Object -First 1
}
}
Add-Type -AssemblyName PresentationCore, PresentationFramework Add-Type -AssemblyName PresentationCore, PresentationFramework
#region Variables #region Variables
@ -8586,19 +8655,12 @@ function Install-WSL
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Name="Window" Name="Window"
Title="WSL" Title="WSL"
MinHeight="400" MinWidth="350" MinHeight="460" MinWidth="350"
SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen"
TextOptions.TextFormattingMode="Display" SnapsToDevicePixels="True" TextOptions.TextFormattingMode="Display" SnapsToDevicePixels="True"
FontFamily="Candara" FontSize="16" ShowInTaskbar="True" FontFamily="Candara" FontSize="16" ShowInTaskbar="True"
Background="#F1F1F1" Foreground="#262626"> Background="#F1F1F1" Foreground="#262626">
<Window.Resources> <Window.Resources>
<Style TargetType="StackPanel" x:Key="PanelContainerStyle">
<Setter Property="Grid.Row" Value="0"/>
<Setter Property="Orientation" Value="Vertical"/>
</Style>
<Style TargetType="StackPanel" x:Key="PanelElementStyle">
<Setter Property="Orientation" Value="Horizontal"/>
</Style>
<Style TargetType="RadioButton"> <Style TargetType="RadioButton">
<Setter Property="VerticalAlignment" Value="Center"/> <Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Margin" Value="10"/> <Setter Property="Margin" Value="10"/>
@ -8618,47 +8680,7 @@ function Install-WSL
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel Name="PanelContainer" Style="{StaticResource PanelContainerStyle}"> <StackPanel Name="PanelContainer" Grid.Row="0"/>
<StackPanel Style="{StaticResource PanelElementStyle}">
<RadioButton Name="RadioButtonUbuntu" GroupName="NixNames" Tag="Ubuntu"/>
<TextBlock Text="Ubuntu"/>
</StackPanel>
<StackPanel Style="{StaticResource PanelElementStyle}">
<RadioButton Name="RadioButtonDebian" GroupName="NixNames" Tag="Debian"/>
<TextBlock Text="Debian GNU/Linux"/>
</StackPanel>
<StackPanel Style="{StaticResource PanelElementStyle}">
<RadioButton Name="RadioButtonKali" GroupName="NixNames" Tag="kali-linux"/>
<TextBlock Text="Kali Linux Rolling"/>
</StackPanel>
<StackPanel Style="{StaticResource PanelElementStyle}">
<RadioButton Name="RadioButtonOpenSuse" GroupName="NixNames" Tag="openSUSE-42"/>
<TextBlock Text="openSUSE Leap 42"/>
</StackPanel>
<StackPanel Style="{StaticResource PanelElementStyle}">
<RadioButton Name="RadioButtonSuse" GroupName="NixNames" Tag="SLES-12"/>
<TextBlock Text="SUSE Linux Enterprise Server v12"/>
</StackPanel>
<StackPanel Style="{StaticResource PanelElementStyle}">
<RadioButton Name="RadioButtonUbuntu16" GroupName="NixNames" Tag="Ubuntu-16.04"/>
<TextBlock Text="Ubuntu 16.04 LTS"/>
</StackPanel>
<StackPanel Style="{StaticResource PanelElementStyle}">
<RadioButton Name="RadioButtonUbuntu18" GroupName="NixNames" Tag="Ubuntu-18.04"/>
<TextBlock Text="Ubuntu 18.04 LTS"/>
</StackPanel>
<StackPanel Style="{StaticResource PanelElementStyle}">
<RadioButton Name="RadioButtonUbuntu20" GroupName="NixNames" Tag="Ubuntu-20.04"/>
<TextBlock Text="Ubuntu 20.04 LTS"/>
</StackPanel>
</StackPanel>
<Button Name="ButtonInstall" Content="Install" Grid.Row="2"/> <Button Name="ButtonInstall" Content="Install" Grid.Row="2"/>
</Grid> </Grid>
</Window> </Window>
@ -8677,7 +8699,11 @@ function Install-WSL
function ButtonInstallClicked function ButtonInstallClicked
{ {
Write-Warning -Message $Script:CommandTag
Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait
$Form.Close()
} }
#endregion #endregion
@ -8685,11 +8711,23 @@ function Install-WSL
$XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process { $XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object -Process {
$control = $Form.FindName($_.Name) $control = $Form.FindName($_.Name)
Set-Variable -Name ($_.Name) -Value $control Set-Variable -Name ($_.Name) -Value $control
if ($Control.Template.TargetType.Name -eq "RadioButton")
{
$Control.Add_Checked({RadioButtonChecked})
} }
foreach ($Distro in $Distros)
{
$Panel = New-Object -TypeName System.Windows.Controls.StackPanel
$RadioButton = New-Object -TypeName System.Windows.Controls.RadioButton
$TextBlock = New-Object -TypeName System.Windows.Controls.TextBlock
$Panel.Orientation = "Horizontal"
$RadioButton.GroupName = "WslDistro"
$RadioButton.Tag = $Distro.Alias
$RadioButton.Add_Checked({RadioButtonChecked})
$TextBlock.Text = $Distro.Distro
$Panel.Children.Add($RadioButton) | Out-Null
$Panel.Children.Add($TextBlock) | Out-Null
$PanelContainer.Children.Add($Panel) | Out-Null
} }
$ButtonInstall.Add_Click({ButtonInstallClicked}) $ButtonInstall.Add_Click({ButtonInstallClicked})
#region Sendkey function #region Sendkey function
@ -8717,7 +8755,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Add-Type @SetForegroundWindow Add-Type @SetForegroundWindow
} }
Get-Process | Where-Object -FilterScript {(($_.ProcessName -eq "powershell") -or ($_.ProcessName -eq "WindowsTerminal")) -and ($_.MainWindowTitle -match "Sophia Script for Windows 10")} | ForEach-Object -Process { Get-Process | Where-Object -FilterScript {(($_.ProcessName -eq "powershell") -or ($_.ProcessName -eq "WindowsTerminal")) -and ($_.MainWindowTitle -match "Sophia Script for Windows 11")} | ForEach-Object -Process {
# Show window, if minimized # Show window, if minimized
[WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10) [WinAPI.ForegroundWindow]::ShowWindowAsync($_.MainWindowHandle, 10)
@ -8739,6 +8777,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Receive updates for other Microsoft products when you update Windows # Receive updates for other Microsoft products when you update Windows
(New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "") (New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "")
# Trigger Windows Update for detecting new updates
(New-Object -ComObject Microsoft.Update.AutoUpdate).DetectNow()
} }
#endregion WSL #endregion WSL
@ -9597,6 +9638,8 @@ public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
Description = $Localization.CleanupNotificationTaskDescription Description = $Localization.CleanupNotificationTaskDescription
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -9780,6 +9823,8 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For
Description = $Localization.FolderTaskDescription -f "%SystemRoot%\SoftwareDistribution\Download" Description = $Localization.FolderTaskDescription -f "%SystemRoot%\SoftwareDistribution\Download"
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -9958,6 +10003,8 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_
Description = $Localization.FolderTaskDescription -f "%TEMP%" Description = $Localization.FolderTaskDescription -f "%TEMP%"
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -11872,11 +11919,7 @@ public static void PostMessage()
} }
# Check if any of scheduled tasks were created. Unless open Task Scheduler # Check if any of scheduled tasks were created. Unless open Task Scheduler
# Check how the script was invoked: via a preset or Function.ps1 if ($Script:ScheduledTasks)
$PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript {
(($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and (($_.Text -eq "CleanupTask -Register") -or ($_.Text -eq "CleanupTask -Register") -or ($_.Text -eq "TempTask -Register")) -or ($_.Text -match "Invoke-Expression")
}
if ($PresetName)
{ {
# Open Task Scheduler # Open Task Scheduler
Start-Process -FilePath taskschd.msc Start-Process -FilePath taskschd.msc

2
src/Sophia_Script_for_Windows_10_LTSC_2021/Sophia.ps1

@ -878,7 +878,7 @@ InstallVCRedist
<# <#
Install the latest .NET Desktop Runtime 6, 7 (x86/x64) Install the latest .NET Desktop Runtime 6, 7 (x86/x64)
Установить последнюю версию .NET Desktop Runtime 6 (x86/x64) Установить последнюю версию .NET Desktop Runtime 6, 7 (x86/x64)
https://dotnet.microsoft.com/en-us/download/dotnet https://dotnet.microsoft.com/en-us/download/dotnet
#> #>

21
src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1

@ -4446,16 +4446,10 @@ function OneDrive
return return
} }
# Check if script was launched from OneDrive folder and preset file has function to uninstall OneDrive
# Check how the script was invoked: via a preset or Function.ps1
$PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript {
(($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and ($_.Text -eq "OneDrive -Uninstall") -or ($_.Text -match "Invoke-Expression")
}
# Check if user is logged into OneDrive account (Microsoft account) # Check if user is logged into OneDrive account (Microsoft account)
$UserEmail = Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Personal -Name UserEmail -ErrorAction Ignore $UserEmail = Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Personal -Name UserEmail -ErrorAction Ignore
if ($PresetName -and $UserEmail) if ($UserEmail)
{ {
# Exit if user accidentally set function in preset to uninstall but he's logged into the app
return return
} }
@ -7714,6 +7708,7 @@ function WinPrtScrFolder
$PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript { $PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript {
(($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and (($_.Text -eq "WinPrtScrFolder -Desktop") -or ($_.Text -match "Invoke-Expression")) (($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and (($_.Text -eq "WinPrtScrFolder -Desktop") -or ($_.Text -match "Invoke-Expression"))
} }
if ($PresetName) if ($PresetName)
{ {
# Get the name of a preset (e.g Sophia.ps1) regardless it was named # Get the name of a preset (e.g Sophia.ps1) regardless it was named
@ -11872,6 +11867,8 @@ public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
Description = $Localization.CleanupNotificationTaskDescription Description = $Localization.CleanupNotificationTaskDescription
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -12055,6 +12052,8 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For
Description = $Localization.FolderTaskDescription -f "%SystemRoot%\SoftwareDistribution\Download" Description = $Localization.FolderTaskDescription -f "%SystemRoot%\SoftwareDistribution\Download"
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -12233,6 +12232,8 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_
Description = $Localization.FolderTaskDescription -f "%TEMP%" Description = $Localization.FolderTaskDescription -f "%TEMP%"
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -14317,11 +14318,7 @@ public static void PostMessage()
} }
# Check if any of scheduled tasks were created. Unless open Task Scheduler # Check if any of scheduled tasks were created. Unless open Task Scheduler
# Check how the script was invoked: via a preset or Function.ps1 if ($Script:ScheduledTasks)
$PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript {
(($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and (($_.Text -eq "CleanupTask -Register") -or ($_.Text -eq "CleanupTask -Register") -or ($_.Text -eq "TempTask -Register")) -or ($_.Text -match "Invoke-Expression")
}
if ($PresetName)
{ {
# Open Task Scheduler # Open Task Scheduler
Start-Process -FilePath taskschd.msc Start-Process -FilePath taskschd.msc

2
src/Sophia_Script_for_Windows_10_PowerShell_7/Sophia.ps1

@ -988,7 +988,7 @@ InstallVCRedist
<# <#
Install the latest .NET Desktop Runtime 6, 7 (x86/x64) Install the latest .NET Desktop Runtime 6, 7 (x86/x64)
Установить последнюю версию .NET Desktop Runtime 6 (x86/x64) Установить последнюю версию .NET Desktop Runtime 6, 7 (x86/x64)
https://dotnet.microsoft.com/en-us/download/dotnet https://dotnet.microsoft.com/en-us/download/dotnet
#> #>

25
src/Sophia_Script_for_Windows_11/Module/Sophia.psm1

@ -7177,6 +7177,7 @@ function WinPrtScrFolder
$PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript { $PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript {
(($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and (($_.Text -eq "WinPrtScrFolder -Desktop") -or ($_.Text -match "Invoke-Expression")) (($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and (($_.Text -eq "WinPrtScrFolder -Desktop") -or ($_.Text -match "Invoke-Expression"))
} }
if ($PresetName) if ($PresetName)
{ {
# Get the name of a preset (e.g Sophia.ps1) regardless it was named # Get the name of a preset (e.g Sophia.ps1) regardless it was named
@ -9351,6 +9352,12 @@ function Install-WSL
Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait
$Form.Close() $Form.Close()
# Receive updates for other Microsoft products when you update Windows
(New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "")
# Trigger Windows Update for detecting new updates
(New-Object -ComObject Microsoft.Update.AutoUpdate).DetectNow()
} }
#endregion #endregion
@ -9421,12 +9428,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Force move the WPF form to the foreground # Force move the WPF form to the foreground
$Window.Add_Loaded({$Window.Activate()}) $Window.Add_Loaded({$Window.Activate()})
$Form.ShowDialog() | Out-Null $Form.ShowDialog() | Out-Null
# Receive updates for other Microsoft products when you update Windows
(New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "")
# Trigger Windows Update for detecting new updates
(New-Object -ComObject Microsoft.Update.AutoUpdate).DetectNow()
} }
#endregion WSL #endregion WSL
@ -11243,6 +11244,8 @@ public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
Description = $Localization.CleanupNotificationTaskDescription Description = $Localization.CleanupNotificationTaskDescription
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -11426,6 +11429,8 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For
Description = $Localization.FolderTaskDescription -f "%SystemRoot%\SoftwareDistribution\Download" Description = $Localization.FolderTaskDescription -f "%SystemRoot%\SoftwareDistribution\Download"
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -11604,6 +11609,8 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_
Description = $Localization.FolderTaskDescription -f "%TEMP%" Description = $Localization.FolderTaskDescription -f "%TEMP%"
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -13632,11 +13639,7 @@ public static void PostMessage()
} }
# Check if any of scheduled tasks were created. Unless open Task Scheduler # Check if any of scheduled tasks were created. Unless open Task Scheduler
# Check how the script was invoked: via a preset or Function.ps1 if ($Script:ScheduledTasks)
$PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript {
(($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and (($_.Text -eq "CleanupTask -Register") -or ($_.Text -eq "CleanupTask -Register") -or ($_.Text -eq "TempTask -Register")) -or ($_.Text -match "Invoke-Expression")
}
if ($PresetName)
{ {
# Open Task Scheduler # Open Task Scheduler
Start-Process -FilePath taskschd.msc Start-Process -FilePath taskschd.msc

33
src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1

@ -3926,16 +3926,10 @@ function OneDrive
return return
} }
# Check if script was launched from OneDrive folder and preset file has function to uninstall OneDrive
# Check how the script was invoked: via a preset or Function.ps1
$PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript {
(($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and ($_.Text -eq "OneDrive -Uninstall") -or ($_.Text -match "Invoke-Expression")
}
# Check if user is logged into OneDrive account (Microsoft account) # Check if user is logged into OneDrive account (Microsoft account)
$UserEmail = Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Personal -Name UserEmail -ErrorAction Ignore $UserEmail = Get-ItemProperty -Path HKCU:\Software\Microsoft\OneDrive\Accounts\Personal -Name UserEmail -ErrorAction Ignore
if ($PresetName -and $UserEmail) if ($UserEmail)
{ {
# Exit if user accidentally set function in preset to uninstall but he's logged into the app
return return
} }
@ -7191,6 +7185,7 @@ function WinPrtScrFolder
$PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript { $PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript {
(($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and (($_.Text -eq "WinPrtScrFolder -Desktop") -or ($_.Text -match "Invoke-Expression")) (($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and (($_.Text -eq "WinPrtScrFolder -Desktop") -or ($_.Text -match "Invoke-Expression"))
} }
if ($PresetName) if ($PresetName)
{ {
# Get the name of a preset (e.g Sophia.ps1) regardless it was named # Get the name of a preset (e.g Sophia.ps1) regardless it was named
@ -9365,6 +9360,12 @@ function Install-WSL
Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait Start-Process -FilePath wsl.exe -ArgumentList "--install --distribution $Script:CommandTag" -Wait
$Form.Close() $Form.Close()
# Receive updates for other Microsoft products when you update Windows
(New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "")
# Trigger Windows Update for detecting new updates
(New-Object -ComObject Microsoft.Update.AutoUpdate).DetectNow()
} }
#endregion #endregion
@ -9435,12 +9436,6 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Force move the WPF form to the foreground # Force move the WPF form to the foreground
$Window.Add_Loaded({$Window.Activate()}) $Window.Add_Loaded({$Window.Activate()})
$Form.ShowDialog() | Out-Null $Form.ShowDialog() | Out-Null
# Receive updates for other Microsoft products when you update Windows
(New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "")
# Trigger Windows Update for detecting new updates
(New-Object -ComObject Microsoft.Update.AutoUpdate).DetectNow()
} }
#endregion WSL #endregion WSL
@ -11277,6 +11272,8 @@ public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
Description = $Localization.CleanupNotificationTaskDescription Description = $Localization.CleanupNotificationTaskDescription
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -11460,6 +11457,8 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For
Description = $Localization.FolderTaskDescription -f "%SystemRoot%\SoftwareDistribution\Download" Description = $Localization.FolderTaskDescription -f "%SystemRoot%\SoftwareDistribution\Download"
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -11638,6 +11637,8 @@ Get-ChildItem -Path `$env:TEMP -Recurse -Force | Where-Object -FilterScript {`$_
Description = $Localization.FolderTaskDescription -f "%TEMP%" Description = $Localization.FolderTaskDescription -f "%TEMP%"
} }
Register-ScheduledTask @Parameters -Force Register-ScheduledTask @Parameters -Force
$Script:ScheduledTasks = $true
} }
"Delete" "Delete"
{ {
@ -13665,11 +13666,7 @@ public static void PostMessage()
} }
# Check if any of scheduled tasks were created. Unless open Task Scheduler # Check if any of scheduled tasks were created. Unless open Task Scheduler
# Check how the script was invoked: via a preset or Function.ps1 if ($Script:ScheduledTasks)
$PresetName = (Get-PSCallStack).Position | Where-Object -FilterScript {
(($_.File -match ".ps1") -and ($_.File -notmatch "Functions.ps1")) -and (($_.Text -eq "CleanupTask -Register") -or ($_.Text -eq "CleanupTask -Register") -or ($_.Text -eq "TempTask -Register")) -or ($_.Text -match "Invoke-Expression")
}
if ($PresetName)
{ {
# Open Task Scheduler # Open Task Scheduler
Start-Process -FilePath taskschd.msc Start-Process -FilePath taskschd.msc

2
src/Sophia_Script_for_Windows_11_PowerShell_7/Sophia.ps1

@ -924,7 +924,7 @@ InstallVCRedist
<# <#
Install the latest .NET Desktop Runtime 6, 7 (x86/x64) Install the latest .NET Desktop Runtime 6, 7 (x86/x64)
Установить последнюю версию .NET Desktop Runtime 6 (x86/x64) Установить последнюю версию .NET Desktop Runtime 6, 7 (x86/x64)
https://dotnet.microsoft.com/en-us/download/dotnet https://dotnet.microsoft.com/en-us/download/dotnet
#> #>

Loading…
Cancel
Save