Browse Source

WindowsScriptHost improved

master
Dmitry Nefedov 6 months ago
parent
commit
2a96da4ce7
  1. 21
      src/Sophia_Script_for_Windows_10/Module/Sophia.psm1
  2. 23
      src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1
  3. 23
      src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1
  4. 21
      src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1
  5. 21
      src/Sophia_Script_for_Windows_11/Module/Sophia.psm1
  6. 25
      src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1

21
src/Sophia_Script_for_Windows_10/Module/Sophia.psm1

@ -148,7 +148,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Detect Windows bitness # Detect Windows bitness
if (-not [System.Environment]::Is64BitOperatingSystem) if (-not [System.Environment]::Is64BitOperatingSystem)
{ {
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message $Localization.UnsupportedOSBitness Write-Warning -Message $Localization.UnsupportedOSBitness
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "https://t.me/sophia_chat" -Verbose Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
@ -871,7 +873,12 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
# Save all opened folders in order to restore them after File Explorer restart # Save all opened folders in order to restore them after File Explorer restart
try
{
$Script: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()
}
catch [System.Management.Automation.PropertyNotFoundException]
{}
<# <#
.SYNOPSIS .SYNOPSIS
@ -997,7 +1004,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# 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
# $_.File has no EndsWith() method # $_.File has no EndsWith() method
Write-Information -MessageData "" -InformationAction Continue Write-Information -MessageData "" -InformationAction Continue
$PresetName = Split-Path -Path (((Get-PSCallStack).Position | Where-Object -FilterScript {$_.File}).File | Where-Object -FilterScript {$_.EndsWith(".ps1")}) -Leaf [string]$PresetName = ((Get-PSCallStack).Position | Where-Object -FilterScript {$_.File}).File | Where-Object -FilterScript {$_.EndsWith(".ps1")}
Write-Verbose -Message ($Localization.CustomizationWarning -f $PresetName) -Verbose Write-Verbose -Message ($Localization.CustomizationWarning -f $PresetName) -Verbose
do do
@ -12577,6 +12584,7 @@ function SoftwareDistributionTask
# Get user's SID the task was created as # Get user's SID the task was created as
$Script:SID = ([xml]$_.xml).Task.Principals.Principal.UserID $Script:SID = ([xml]$_.xml).Task.Principals.Principal.UserID
} }
# Convert SID to username # Convert SID to username
$TaskUserAccount = (New-Object System.Security.Principal.SecurityIdentifier($SID)).Translate([System.Security.Principal.NTAccount]).Value -split "\\" | Select-Object -Last 1 $TaskUserAccount = (New-Object System.Security.Principal.SecurityIdentifier($SID)).Translate([System.Security.Principal.NTAccount]).Value -split "\\" | Select-Object -Last 1
@ -13686,6 +13694,14 @@ function WindowsScriptHost
{ {
"Disable" "Disable"
{ {
# Check if any scheduled tasks were created before, because they rely on Windows Host running vbs files
Get-ScheduledTask -TaskName SoftwareDistribution, Temp, "Windows Cleanup", "Windows Cleanup Notification" | ForEach-Object -Process {
if ($_.State -eq "Ready")
{
continue
}
}
if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings")) if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings"))
{ {
New-Item -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings" -Force New-Item -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings" -Force
@ -14862,6 +14878,8 @@ public static void PostMessage()
Start-Sleep -Seconds 3 Start-Sleep -Seconds 3
# Restoring closed folders # Restoring closed folders
if (Get-Variable -Name OpenedFolder -ErrorAction Ignore)
{
foreach ($Script:OpenedFolder in $Script:OpenedFolders) foreach ($Script:OpenedFolder in $Script:OpenedFolders)
{ {
if (Test-Path -Path $Script:OpenedFolder) if (Test-Path -Path $Script:OpenedFolder)
@ -14869,6 +14887,7 @@ public static void PostMessage()
Start-Process -FilePath explorer -ArgumentList $Script:OpenedFolder Start-Process -FilePath explorer -ArgumentList $Script:OpenedFolder
} }
} }
}
# Check whether any of scheduled tasks were created. Unless open Task Scheduler # Check whether any of scheduled tasks were created. Unless open Task Scheduler
if ($Script:ScheduledTasks) if ($Script:ScheduledTasks)

23
src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1

@ -148,7 +148,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Detect Windows bitness # Detect Windows bitness
if (-not [System.Environment]::Is64BitOperatingSystem) if (-not [System.Environment]::Is64BitOperatingSystem)
{ {
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message $Localization.UnsupportedOSBitness Write-Warning -Message $Localization.UnsupportedOSBitness
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "https://t.me/sophia_chat" -Verbose Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
@ -584,7 +586,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Detect Windows build version # Detect Windows build version
if ((Get-WindowsEdition -Online).Edition -notmatch "EnterpriseS") if ((Get-WindowsEdition -Online).Edition -notmatch "EnterpriseS")
{ {
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message $Localization.UnsupportedOSBuild Write-Warning -Message $Localization.UnsupportedOSBuild
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "https://t.me/sophia_chat" -Verbose Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
@ -839,7 +843,12 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
# Save all opened folders in order to restore them after File Explorer restart # Save all opened folders in order to restore them after File Explorer restart
try
{
$Script: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()
}
catch [System.Management.Automation.PropertyNotFoundException]
{}
<# <#
.SYNOPSIS .SYNOPSIS
@ -965,7 +974,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# 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
# $_.File has no EndsWith() method # $_.File has no EndsWith() method
Write-Information -MessageData "" -InformationAction Continue Write-Information -MessageData "" -InformationAction Continue
$PresetName = Split-Path -Path (((Get-PSCallStack).Position | Where-Object -FilterScript {$_.File}).File | Where-Object -FilterScript {$_.EndsWith(".ps1")}) -Leaf [string]$PresetName = ((Get-PSCallStack).Position | Where-Object -FilterScript {$_.File}).File | Where-Object -FilterScript {$_.EndsWith(".ps1")}
Write-Verbose -Message ($Localization.CustomizationWarning -f $PresetName) -Verbose Write-Verbose -Message ($Localization.CustomizationWarning -f $PresetName) -Verbose
do do
@ -9429,6 +9438,7 @@ function SoftwareDistributionTask
# Get user's SID the task was created as # Get user's SID the task was created as
$Script:SID = ([xml]$_.xml).Task.Principals.Principal.UserID $Script:SID = ([xml]$_.xml).Task.Principals.Principal.UserID
} }
# Convert SID to username # Convert SID to username
$TaskUserAccount = (New-Object System.Security.Principal.SecurityIdentifier($SID)).Translate([System.Security.Principal.NTAccount]).Value -split "\\" | Select-Object -Last 1 $TaskUserAccount = (New-Object System.Security.Principal.SecurityIdentifier($SID)).Translate([System.Security.Principal.NTAccount]).Value -split "\\" | Select-Object -Last 1
@ -10538,6 +10548,14 @@ function WindowsScriptHost
{ {
"Disable" "Disable"
{ {
# Check if any scheduled tasks were created before, because they rely on Windows Host running vbs files
Get-ScheduledTask -TaskName SoftwareDistribution, Temp, "Windows Cleanup", "Windows Cleanup Notification" | ForEach-Object -Process {
if ($_.State -eq "Ready")
{
continue
}
}
if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings")) if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings"))
{ {
New-Item -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings" -Force New-Item -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings" -Force
@ -11637,6 +11655,8 @@ public static void PostMessage()
Start-Sleep -Seconds 3 Start-Sleep -Seconds 3
# Restoring closed folders # Restoring closed folders
if (Get-Variable -Name OpenedFolder -ErrorAction Ignore)
{
foreach ($Script:OpenedFolder in $Script:OpenedFolders) foreach ($Script:OpenedFolder in $Script:OpenedFolders)
{ {
if (Test-Path -Path $Script:OpenedFolder) if (Test-Path -Path $Script:OpenedFolder)
@ -11644,6 +11664,7 @@ public static void PostMessage()
Start-Process -FilePath explorer -ArgumentList $Script:OpenedFolder Start-Process -FilePath explorer -ArgumentList $Script:OpenedFolder
} }
} }
}
# Check whether any of scheduled tasks were created. Unless open Task Scheduler # Check whether any of scheduled tasks were created. Unless open Task Scheduler
if ($Script:ScheduledTasks) if ($Script:ScheduledTasks)

23
src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1

@ -148,7 +148,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Detect Windows bitness # Detect Windows bitness
if (-not [System.Environment]::Is64BitOperatingSystem) if (-not [System.Environment]::Is64BitOperatingSystem)
{ {
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message $Localization.UnsupportedOSBitness Write-Warning -Message $Localization.UnsupportedOSBitness
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "https://t.me/sophia_chat" -Verbose Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
@ -584,7 +586,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Detect Windows build version # Detect Windows build version
if ((Get-WindowsEdition -Online).Edition -notmatch "EnterpriseS") if ((Get-WindowsEdition -Online).Edition -notmatch "EnterpriseS")
{ {
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message $Localization.UnsupportedOSBuild Write-Warning -Message $Localization.UnsupportedOSBuild
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "https://t.me/sophia_chat" -Verbose Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
@ -839,7 +843,12 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
# Save all opened folders in order to restore them after File Explorer restart # Save all opened folders in order to restore them after File Explorer restart
try
{
$Script: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()
}
catch [System.Management.Automation.PropertyNotFoundException]
{}
<# <#
.SYNOPSIS .SYNOPSIS
@ -965,7 +974,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# 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
# $_.File has no EndsWith() method # $_.File has no EndsWith() method
Write-Information -MessageData "" -InformationAction Continue Write-Information -MessageData "" -InformationAction Continue
$PresetName = Split-Path -Path (((Get-PSCallStack).Position | Where-Object -FilterScript {$_.File}).File | Where-Object -FilterScript {$_.EndsWith(".ps1")}) -Leaf [string]$PresetName = ((Get-PSCallStack).Position | Where-Object -FilterScript {$_.File}).File | Where-Object -FilterScript {$_.EndsWith(".ps1")}
Write-Verbose -Message ($Localization.CustomizationWarning -f $PresetName) -Verbose Write-Verbose -Message ($Localization.CustomizationWarning -f $PresetName) -Verbose
do do
@ -10563,6 +10572,7 @@ function SoftwareDistributionTask
# Get user's SID the task was created as # Get user's SID the task was created as
$Script:SID = ([xml]$_.xml).Task.Principals.Principal.UserID $Script:SID = ([xml]$_.xml).Task.Principals.Principal.UserID
} }
# Convert SID to username # Convert SID to username
$TaskUserAccount = (New-Object System.Security.Principal.SecurityIdentifier($SID)).Translate([System.Security.Principal.NTAccount]).Value -split "\\" | Select-Object -Last 1 $TaskUserAccount = (New-Object System.Security.Principal.SecurityIdentifier($SID)).Translate([System.Security.Principal.NTAccount]).Value -split "\\" | Select-Object -Last 1
@ -11672,6 +11682,14 @@ function WindowsScriptHost
{ {
"Disable" "Disable"
{ {
# Check if any scheduled tasks were created before, because they rely on Windows Host running vbs files
Get-ScheduledTask -TaskName SoftwareDistribution, Temp, "Windows Cleanup", "Windows Cleanup Notification" | ForEach-Object -Process {
if ($_.State -eq "Ready")
{
continue
}
}
if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings")) if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings"))
{ {
New-Item -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings" -Force New-Item -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings" -Force
@ -12831,6 +12849,8 @@ public static void PostMessage()
Start-Sleep -Seconds 3 Start-Sleep -Seconds 3
# Restoring closed folders # Restoring closed folders
if (Get-Variable -Name OpenedFolder -ErrorAction Ignore)
{
foreach ($Script:OpenedFolder in $Script:OpenedFolders) foreach ($Script:OpenedFolder in $Script:OpenedFolders)
{ {
if (Test-Path -Path $Script:OpenedFolder) if (Test-Path -Path $Script:OpenedFolder)
@ -12838,6 +12858,7 @@ public static void PostMessage()
Start-Process -FilePath explorer -ArgumentList $Script:OpenedFolder Start-Process -FilePath explorer -ArgumentList $Script:OpenedFolder
} }
} }
}
# Check whether any of scheduled tasks were created. Unless open Task Scheduler # Check whether any of scheduled tasks were created. Unless open Task Scheduler
if ($Script:ScheduledTasks) if ($Script:ScheduledTasks)

21
src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1

@ -147,7 +147,9 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# Detect Windows bitness # Detect Windows bitness
if (-not [System.Environment]::Is64BitOperatingSystem) if (-not [System.Environment]::Is64BitOperatingSystem)
{ {
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message $Localization.UnsupportedOSBitness Write-Warning -Message $Localization.UnsupportedOSBitness
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "https://t.me/sophia_chat" -Verbose Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
@ -875,7 +877,12 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
# Save all opened folders in order to restore them after File Explorer restart # Save all opened folders in order to restore them after File Explorer restart
try
{
$Script: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()
}
catch [System.Management.Automation.PropertyNotFoundException]
{}
<# <#
.SYNOPSIS .SYNOPSIS
@ -1001,7 +1008,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# 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
# $_.File has no EndsWith() method # $_.File has no EndsWith() method
Write-Information -MessageData "" -InformationAction Continue Write-Information -MessageData "" -InformationAction Continue
$PresetName = Split-Path -Path (((Get-PSCallStack).Position | Where-Object -FilterScript {$_.File}).File | Where-Object -FilterScript {$_.EndsWith(".ps1")}) -Leaf [string]$PresetName = ((Get-PSCallStack).Position | Where-Object -FilterScript {$_.File}).File | Where-Object -FilterScript {$_.EndsWith(".ps1")}
Write-Verbose -Message ($Localization.CustomizationWarning -f $PresetName) -Verbose Write-Verbose -Message ($Localization.CustomizationWarning -f $PresetName) -Verbose
do do
@ -12593,6 +12600,7 @@ function SoftwareDistributionTask
# Get user's SID the task was created as # Get user's SID the task was created as
$Script:SID = ([xml]$_.xml).Task.Principals.Principal.UserID $Script:SID = ([xml]$_.xml).Task.Principals.Principal.UserID
} }
# Convert SID to username # Convert SID to username
$TaskUserAccount = (New-Object System.Security.Principal.SecurityIdentifier($SID)).Translate([System.Security.Principal.NTAccount]).Value -split "\\" | Select-Object -Last 1 $TaskUserAccount = (New-Object System.Security.Principal.SecurityIdentifier($SID)).Translate([System.Security.Principal.NTAccount]).Value -split "\\" | Select-Object -Last 1
@ -13702,6 +13710,14 @@ function WindowsScriptHost
{ {
"Disable" "Disable"
{ {
# Check if any scheduled tasks were created before, because they rely on Windows Host running vbs files
Get-ScheduledTask -TaskName SoftwareDistribution, Temp, "Windows Cleanup", "Windows Cleanup Notification" | ForEach-Object -Process {
if ($_.State -eq "Ready")
{
continue
}
}
if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings")) if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings"))
{ {
New-Item -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings" -Force New-Item -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings" -Force
@ -14878,6 +14894,8 @@ public static void PostMessage()
Start-Sleep -Seconds 3 Start-Sleep -Seconds 3
# Restoring closed folders # Restoring closed folders
if (Get-Variable -Name OpenedFolder -ErrorAction Ignore)
{
foreach ($Script:OpenedFolder in $Script:OpenedFolders) foreach ($Script:OpenedFolder in $Script:OpenedFolders)
{ {
if (Test-Path -Path $Script:OpenedFolder) if (Test-Path -Path $Script:OpenedFolder)
@ -14885,6 +14903,7 @@ public static void PostMessage()
Start-Process -FilePath explorer -ArgumentList $Script:OpenedFolder Start-Process -FilePath explorer -ArgumentList $Script:OpenedFolder
} }
} }
}
# Check whether any of scheduled tasks were created. Unless open Task Scheduler # Check whether any of scheduled tasks were created. Unless open Task Scheduler
if ($Script:ScheduledTasks) if ($Script:ScheduledTasks)

21
src/Sophia_Script_for_Windows_11/Module/Sophia.psm1

@ -861,7 +861,12 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
# Save all opened folders in order to restore them after File Explorer restart # Save all opened folders in order to restore them after File Explorer restart
try
{
$Script: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()
}
catch [System.Management.Automation.PropertyNotFoundException]
{}
<# <#
.SYNOPSIS .SYNOPSIS
@ -987,7 +992,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
# 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
# $_.File has no EndsWith() method # $_.File has no EndsWith() method
Write-Information -MessageData "" -InformationAction Continue Write-Information -MessageData "" -InformationAction Continue
$PresetName = Split-Path -Path (((Get-PSCallStack).Position | Where-Object -FilterScript {$_.File}).File | Where-Object -FilterScript {$_.EndsWith(".ps1")}) -Leaf [string]$PresetName = ((Get-PSCallStack).Position | Where-Object -FilterScript {$_.File}).File | Where-Object -FilterScript {$_.EndsWith(".ps1")}
Write-Verbose -Message ($Localization.CustomizationWarning -f $PresetName) -Verbose Write-Verbose -Message ($Localization.CustomizationWarning -f $PresetName) -Verbose
do do
@ -11752,6 +11757,7 @@ function SoftwareDistributionTask
# Get user's SID the task was created as # Get user's SID the task was created as
$Script:SID = ([xml]$_.xml).Task.Principals.Principal.UserID $Script:SID = ([xml]$_.xml).Task.Principals.Principal.UserID
} }
# Convert SID to username # Convert SID to username
$TaskUserAccount = (New-Object System.Security.Principal.SecurityIdentifier($SID)).Translate([System.Security.Principal.NTAccount]).Value -split "\\" | Select-Object -Last 1 $TaskUserAccount = (New-Object System.Security.Principal.SecurityIdentifier($SID)).Translate([System.Security.Principal.NTAccount]).Value -split "\\" | Select-Object -Last 1
@ -12836,7 +12842,7 @@ function SaveZoneInformation
.NOTES .NOTES
Current user Current user
#> #>
function WindowsScriptHost ### function WindowsScriptHost
{ {
param param
( (
@ -12859,6 +12865,14 @@ function WindowsScriptHost ###
{ {
"Disable" "Disable"
{ {
# Check if any scheduled tasks were created before, because they rely on Windows Host running vbs files
Get-ScheduledTask -TaskName SoftwareDistribution, Temp, "Windows Cleanup", "Windows Cleanup Notification" | ForEach-Object -Process {
if ($_.State -eq "Ready")
{
continue
}
}
if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings")) if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings"))
{ {
New-Item -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings" -Force New-Item -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings" -Force
@ -14038,6 +14052,8 @@ public static void PostMessage()
Start-Sleep -Seconds 3 Start-Sleep -Seconds 3
# Restoring closed folders # Restoring closed folders
if (Get-Variable -Name OpenedFolder -ErrorAction Ignore)
{
foreach ($Script:OpenedFolder in $Script:OpenedFolders) foreach ($Script:OpenedFolder in $Script:OpenedFolders)
{ {
if (Test-Path -Path $Script:OpenedFolder) if (Test-Path -Path $Script:OpenedFolder)
@ -14045,6 +14061,7 @@ public static void PostMessage()
Start-Process -FilePath explorer -ArgumentList $Script:OpenedFolder Start-Process -FilePath explorer -ArgumentList $Script:OpenedFolder
} }
} }
}
# Check whether any of scheduled tasks were created. Unless open Task Scheduler # Check whether any of scheduled tasks were created. Unless open Task Scheduler
if ($Script:ScheduledTasks) if ($Script:ScheduledTasks)

25
src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1

@ -306,7 +306,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd);
exit exit
} }
pause
# Check whether Windows Feature Experience Pack was removed by harmful tweakers # Check whether Windows Feature Experience Pack was removed by harmful tweakers
if (-not (Get-AppxPackage -Name MicrosoftWindows.Client.CBS)) if (-not (Get-AppxPackage -Name MicrosoftWindows.Client.CBS))
{ {
@ -598,10 +598,12 @@ pause
exit exit
} }
if ((Get-WindowsEdition -Online).Edition -notmatch "EnterpriseS") if ((Get-WindowsEdition -Online).Edition -match "EnterpriseS")
{ {
# Will be removed when Windows 11 Enterprise LTSC will be released officially this Autumn along side with 24H2 # Will be removed when Windows 11 Enterprise LTSC will be released officially this Autumn along side with 24H2
Write-Information -MessageData "" -InformationAction Continue
Write-Warning -Message "You're using a leaked Windows 11 Enterprise LTSC image. The official release set to November." Write-Warning -Message "You're using a leaked Windows 11 Enterprise LTSC image. The official release set to November."
Write-Information -MessageData "" -InformationAction Continue
Write-Verbose -Message "https://t.me/sophia_chat" -Verbose Write-Verbose -Message "https://t.me/sophia_chat" -Verbose
Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose Write-Verbose -Message "https://discord.gg/sSryhaEv79" -Verbose
@ -863,7 +865,12 @@ pause
Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore Get-ChildItem -Path "$env:TEMP\Computer.txt", "$env:TEMP\User.txt" -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
# Save all opened folders in order to restore them after File Explorer restart # Save all opened folders in order to restore them after File Explorer restart
try
{
$Script: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()
}
catch [System.Management.Automation.PropertyNotFoundException]
{}
<# <#
.SYNOPSIS .SYNOPSIS
@ -989,7 +996,7 @@ pause
# 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
# $_.File has no EndsWith() method # $_.File has no EndsWith() method
Write-Information -MessageData "" -InformationAction Continue Write-Information -MessageData "" -InformationAction Continue
$PresetName = Split-Path -Path (((Get-PSCallStack).Position | Where-Object -FilterScript {$_.File}).File | Where-Object -FilterScript {$_.EndsWith(".ps1")}) -Leaf [string]$PresetName = ((Get-PSCallStack).Position | Where-Object -FilterScript {$_.File}).File | Where-Object -FilterScript {$_.EndsWith(".ps1")}
Write-Verbose -Message ($Localization.CustomizationWarning -f $PresetName) -Verbose Write-Verbose -Message ($Localization.CustomizationWarning -f $PresetName) -Verbose
do do
@ -11766,6 +11773,7 @@ function SoftwareDistributionTask
# Get user's SID the task was created as # Get user's SID the task was created as
$Script:SID = ([xml]$_.xml).Task.Principals.Principal.UserID $Script:SID = ([xml]$_.xml).Task.Principals.Principal.UserID
} }
# Convert SID to username # Convert SID to username
$TaskUserAccount = (New-Object System.Security.Principal.SecurityIdentifier($SID)).Translate([System.Security.Principal.NTAccount]).Value -split "\\" | Select-Object -Last 1 $TaskUserAccount = (New-Object System.Security.Principal.SecurityIdentifier($SID)).Translate([System.Security.Principal.NTAccount]).Value -split "\\" | Select-Object -Last 1
@ -12873,6 +12881,14 @@ function WindowsScriptHost
{ {
"Disable" "Disable"
{ {
# Check if any scheduled tasks were created before, because they rely on Windows Host running vbs files
Get-ScheduledTask -TaskName SoftwareDistribution, Temp, "Windows Cleanup", "Windows Cleanup Notification" | ForEach-Object -Process {
if ($_.State -eq "Ready")
{
continue
}
}
if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings")) if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings"))
{ {
New-Item -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings" -Force New-Item -Path "HKCU:\Software\Microsoft\Windows Script Host\Settings" -Force
@ -14052,6 +14068,8 @@ public static void PostMessage()
Start-Sleep -Seconds 3 Start-Sleep -Seconds 3
# Restoring closed folders # Restoring closed folders
if (Get-Variable -Name OpenedFolder -ErrorAction Ignore)
{
foreach ($Script:OpenedFolder in $Script:OpenedFolders) foreach ($Script:OpenedFolder in $Script:OpenedFolders)
{ {
if (Test-Path -Path $Script:OpenedFolder) if (Test-Path -Path $Script:OpenedFolder)
@ -14059,6 +14077,7 @@ public static void PostMessage()
Start-Process -FilePath explorer -ArgumentList $Script:OpenedFolder Start-Process -FilePath explorer -ArgumentList $Script:OpenedFolder
} }
} }
}
# Check whether any of scheduled tasks were created. Unless open Task Scheduler # Check whether any of scheduled tasks were created. Unless open Task Scheduler
if ($Script:ScheduledTasks) if ($Script:ScheduledTasks)

Loading…
Cancel
Save