@ -4273,6 +4273,122 @@ public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, uint
}
[WinAPI.SystemParamInfo] :: SystemParametersInfo ( 0x0057 , 0 , $null , 0 )
}
<#
. SYNOPSIS
Files and folders grouping in the Downloads folder
. PARAMETER None
Do not group files and folder in the Downloads folder
. PARAMETER Default
Group files and folder by date modified in the Downloads folder ( default value )
. EXAMPLE
FolderGroupBy -None
. EXAMPLE
FolderGroupBy -Default
. NOTES
Current user
#>
function FolderGroupBy
{
param
(
[ Parameter (
Mandatory = $true ,
ParameterSetName = " None "
) ]
[switch]
$None ,
[ Parameter (
Mandatory = $true ,
ParameterSetName = " Default "
) ]
[switch]
$Default
)
switch ( $PSCmdlet . ParameterSetName )
{
" None "
{
# Clear any Common Dialog views
Get-ChildItem -Path " HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\*\Shell " -Recurse | Where-Object -FilterScript { $_ . PSChildName -eq " {885A186E-A440-4ADA-812B-DB871B942259} " } | Remove-Item -Force
# https://learn.microsoft.com/en-us/windows/win32/properties/props-system-null
if ( -not ( Test-Path -Path " HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000} " ) )
{
New-Item -Path " HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000} " -Force
}
New-ItemProperty -Path " HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000} " -Name ColumnList -PropertyType String -Value " System.Null " -Force
New-ItemProperty -Path " HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000} " -Name GroupBy -PropertyType String -Value " System.Null " -Force
New-ItemProperty -Path " HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000} " -Name LogicalViewMode -PropertyType DWord -Value 1 -Force
New-ItemProperty -Path " HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000} " -Name Name -PropertyType String -Value NoName -Force
New-ItemProperty -Path " HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000} " -Name Order -PropertyType DWord -Value 0 -Force
New-ItemProperty -Path " HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000} " -Name PrimaryProperty -PropertyType String -Value " System.ItemNameDisplay " -Force
New-ItemProperty -Path " HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259}\TopViews\{00000000-0000-0000-0000-000000000000} " -Name SortByList -PropertyType String -Value " prop:System.ItemNameDisplay " -Force
}
" Default "
{
Remove-Item -Path " HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{885a186e-a440-4ada-812b-db871b942259} " -Recurse -Force -ErrorAction Ignore
}
}
}
<#
. SYNOPSIS
Expand to current folder in navigation pane
. PARAMETER Disable
Do not expand to open folder on navigation pane ( default value )
. PARAMETER Enable
Expand to open folder on navigation pane
. EXAMPLE
NavigationPaneExpand -Disable
. EXAMPLE
NavigationPaneExpand -Enable
. NOTES
Current user
#>
function NavigationPaneExpand
{
param
(
[ Parameter (
Mandatory = $true ,
ParameterSetName = " Disable "
) ]
[switch]
$Disable ,
[ Parameter (
Mandatory = $true ,
ParameterSetName = " Enable "
) ]
[switch]
$Enable
)
switch ( $PSCmdlet . ParameterSetName )
{
" Disable "
{
Remove-ItemProperty -Path HKCU : \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced -Name NavPaneExpandToCurrentFolder -Force -ErrorAction Ignore
}
" Enable "
{
New-ItemProperty -Path HKCU : \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Advanced -Name NavPaneExpandToCurrentFolder -PropertyType DWord -Value 1 -Force
}
}
}
#endregion UI & Personalization
#region OneDrive
@ -11843,7 +11959,7 @@ function SoftwareDistributionTask
" Register "
{
# Checking if we're trying to create the task when it was already created as another user
if ( Get-ScheduledTask -TaskPath " \Sophia\ " -TaskName SoftwareDistribution )
if ( Get-ScheduledTask -TaskPath " \Sophia\ " -TaskName SoftwareDistribution -ErrorAction Ignore )
{
# Also we can parse $env:SystemRoot\System32\Tasks\Sophia\SoftwareDistribution to check if the task was created
$ScheduleService = New-Object -ComObject Schedule . Service
@ -12021,7 +12137,7 @@ function TempTask
" Register "
{
# Checking if we're trying to create the task when it was already created as another user
if ( Get-ScheduledTask -TaskPath " \Sophia\ " -TaskName Temp )
if ( Get-ScheduledTask -TaskPath " \Sophia\ " -TaskName Temp -ErrorAction Ignore )
{
# Also we can parse $env:SystemRoot\System32\Tasks\Sophia\Temp to check if the task was created
$ScheduleService = New-Object -ComObject Schedule . Service
@ -14071,9 +14187,10 @@ function UpdateLGPEPolicies
}
#endregion Update Policies
#region Refresh Environment
function RefreshEnvironment
#region Post Actions
function PostActions
{
#region Refresh Environment
$UpdateEnvironment = @ {
Namespace = " WinAPI "
Name = " UpdateEnvironment "
@ -14132,7 +14249,9 @@ public static void PostMessage()
# Restart the Start menu
Stop-Process -Name StartMenuExperienceHost -Force -ErrorAction Ignore
#endregion Refresh Environment
#region Other actions
# Turn on Controlled folder access if it was turned off
if ( $Script:DefenderEnabled )
{
@ -14142,6 +14261,12 @@ public static void PostMessage()
}
}
if ( $Script:RegionChanged )
{
# Set the original region ID
Set-WinHomeLocation -GeoId $Script:Region
}
# Persist Sophia notifications to prevent to immediately disappear from Action Center
if ( -not ( Test-Path -Path HKCU : \ Software \ Microsoft \ Windows \ CurrentVersion \ Notifications \ Settings \ Sophia ) )
{
@ -14158,9 +14283,52 @@ public static void PostMessage()
# Determines whether the app can be seen in Settings where the user can turn notifications on or off
New-ItemProperty -Path Registry :: HKEY_CLASSES_ROOT \ AppUserModelId \ Sophia -Name ShowInSettings -Value 0 -PropertyType DWord -Force
Add-Type -AssemblyName " $ PSScriptRoot\..\bin\WinRT.Runtime.dll "
Add-Type -AssemblyName " $ PSScriptRoot\..\bin\Microsoft.Windows.SDK.NET.dll "
[ Windows . UI . Notifications . ToastNotificationManager , Windows . UI . Notifications , ContentType = WindowsRuntime ] | Out-Null
[ Windows . Data . Xml . Dom . XmlDocument , Windows . Data . Xml . Dom . XmlDocument , ContentType = WindowsRuntime ] | Out-Null
# Apply policies found in registry to re-build database database due to gpedit.msc relies in its' own database
if ( ( Test-Path -Path " $ env:TEMP\Computer.txt " ) -or ( Test-Path -Path " $ env:TEMP\User.txt " ) )
{
if ( Test-Path -Path " $ env:TEMP\Computer.txt " )
{
& " $ PSScriptRoot\..\bin\LGPO.exe " / t " $ env:TEMP\Computer.txt "
}
if ( Test-Path -Path " $ env:TEMP\User.txt " )
{
& " $ PSScriptRoot\..\bin\LGPO.exe " / t " $ env:TEMP\User.txt "
}
gpupdate / force
}
# PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word
Get-ChildItem -Path " $ env:TEMP\Computer.txt " , " $ env:TEMP\User.txt " -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
Stop-Process -Name explorer -Force
Start-Sleep -Seconds 3
# Restoring closed folders
foreach ( $Script:OpenedFolder in $Script:OpenedFolders )
{
if ( Test-Path -Path $Script:OpenedFolder )
{
Start-Process -FilePath explorer -ArgumentList $Script:OpenedFolder
}
}
# Check if any of scheduled tasks were created. Unless open Task Scheduler
# 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 " CleanupTask -Register " ) -or ( $_ . Text -eq " CleanupTask -Register " ) -or ( $_ . Text -eq " TempTask -Register " ) ) -or ( $_ . Text -match " Invoke-Expression " )
}
if ( $PresetName )
{
# Open Task Scheduler
Start-Process -FilePath taskschd . msc
}
#endregion Other actions
#region Toast notifications
# Telegram group
[xml] $ToastTemplate = @ "
< toast duration = " Long " scenario = " reminder " >
@ -14241,58 +14409,11 @@ public static void PostMessage()
$ToastMessage = [Windows.UI.Notifications.ToastNotification] :: New ( $ToastXML )
[Windows.UI.Notifications.ToastNotificationManager] :: CreateToastNotifier ( " Sophia " ) . Show ( $ToastMessage )
if ( ( Test-Path -Path " $ env:TEMP\Computer.txt " ) -or ( Test-Path -Path " $ env:TEMP\User.txt " ) )
{
if ( Test-Path -Path " $ env:TEMP\Computer.txt " )
{
& " $ PSScriptRoot\..\bin\LGPO.exe " / t " $ env:TEMP\Computer.txt "
}
if ( Test-Path -Path " $ env:TEMP\User.txt " )
{
& " $ PSScriptRoot\..\bin\LGPO.exe " / t " $ env:TEMP\User.txt "
}
gpupdate / force
}
# [WinAPI.UpdateEnvironment]::Refresh() makes so that Meet Now icon returns even if was hid before, so we need to check which function was called previously
if ( $Script:MeetNow )
{
MeetNow -Show
}
elseif ( $Script:MeetNow -eq $false )
{
MeetNow -Hide
}
# PowerShell 5.1 (7.3 too) interprets 8.3 file name literally, if an environment variable contains a non-latin word
Get-ChildItem -Path " $ env:TEMP\Computer.txt " , " $ env:TEMP\User.txt " -Force -ErrorAction Ignore | Remove-Item -Recurse -Force -ErrorAction Ignore
Stop-Process -Name explorer -Force
Start-Sleep -Seconds 3
# Restoring closed folders
foreach ( $Script:OpenedFolder in $Script:OpenedFolders )
{
if ( Test-Path -Path $Script:OpenedFolder )
{
Start-Process -FilePath explorer -ArgumentList $Script:OpenedFolder
}
}
# Check if any of scheduled tasks were created. Unless open Task Scheduler
# 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 " CleanupTask -Register " ) -or ( $_ . Text -eq " CleanupTask -Register " ) -or ( $_ . Text -eq " TempTask -Register " ) ) -or ( $_ . Text -match " Invoke-Expression " )
}
if ( $PresetName )
{
# Open Task Scheduler
Start-Process -FilePath taskschd . msc
}
#endregion Toast notifications
}
#endregion Post Actions
#region Errors
function Errors
{
if ( $Global:Error )
@ -14315,4 +14436,4 @@ function Errors
Write-Information -MessageData " " -InformationAction Continue
Write-Warning -Message $Localization . RestartWarning
}
#endregion Refresh Environment
#endregion Errors