diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index 583cdff8..812e9c8e 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -842,6 +842,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); $hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData} } } + # Save in UTF8 without BOM $hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts" @@ -1169,6 +1170,7 @@ $($Type):$($Value)`n $Path = "$env:TEMP\User.txt" } + # Save in UTF8 without BOM Add-Content -Path $Path -Value $Policy -Encoding Default -Force } #endregion Additional function @@ -12261,7 +12263,7 @@ function CleanupTask # 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\'' -TaskName ''Windows Cleanup''}"' -Force - $CleanupTask = @" + $CleanupTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -12296,17 +12298,17 @@ Start-Sleep -Seconds 3 New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTask -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTaskPS -Encoding UTF8 -Force # Create vbs script that will help us calling Windows_Cleanup.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $CleanupTask = @" + $CleanupTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup.ps1", 0 "@ # Save in UTF8 without BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTask -Encoding Default -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTaskVBS -Encoding Default -Force # Create "Windows Cleanup" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -12328,7 +12330,7 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) # https://github.com/DCourtel/Windows_10_Focus_Assist/blob/master/FocusAssistLibrary/FocusAssistLib.cs # https://redplait.blogspot.com/2018/07/wnf-ids-from-perfntcdll-adk-version.html - $ToastNotification = @" + $ToastNotificationPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -12446,18 +12448,19 @@ while ([WinAPI.Focus]::GetFocusAssistState() -ne "OFF") "@ # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotification -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotificationPS -Encoding UTF8 -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding UTF8).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding UTF8 -Force # Create vbs script that will help us calling Windows_Cleanup_Notification.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $ToastNotification = @" + $ToastNotificationVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotification -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotificationVBS -Encoding Default -Force # Create the "Windows Cleanup Notification" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -12651,7 +12654,7 @@ function SoftwareDistributionTask # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) # https://github.com/DCourtel/Windows_10_Focus_Assist/blob/master/FocusAssistLibrary/FocusAssistLib.cs # https://redplait.blogspot.com/2018/07/wnf-ids-from-perfntcdll-adk-version.html - $SoftwareDistributionTask = @" + $SoftwareDistributionTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -12769,18 +12772,19 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Value $SoftwareDistributionTask -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Value $SoftwareDistributionTaskPS -Encoding UTF8 -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Encoding UTF8).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Encoding UTF8 -Force # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $SoftwareDistributionTask = @" + $SoftwareDistributionTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\SoftwareDistributionTask.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTask -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTaskVBS -Encoding Default -Force # Create the "SoftwareDistribution" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -12961,7 +12965,7 @@ function TempTask # We have to call PowerShell script via another VBS script silently because VBS has appropriate feature to suppress console appearing (none of other workarounds work) # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) - $TempTask = @" + $TempTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -13092,18 +13096,19 @@ Remove-Item -Path `$Paths -Recurse -Force New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Value $TempTask -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Value $TempTaskPS -Encoding UTF8 -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Encoding UTF8).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Encoding UTF8 -Force # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $TempTask = @" + $TempTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\TempTask.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTask -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTaskVBS -Encoding Default -Force # Create the "Temp" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 index 440c420e..f365ca7e 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2019/Module/Sophia.psm1 @@ -812,6 +812,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); $hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData} } } + # Save in UTF8 without BOM $hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts" @@ -1139,6 +1140,7 @@ $($Type):$($Value)`n $Path = "$env:TEMP\User.txt" } + # Save in UTF8 without BOM Add-Content -Path $Path -Value $Policy -Encoding Default -Force } #endregion Additional function @@ -9115,7 +9117,7 @@ function CleanupTask # 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\'' -TaskName ''Windows Cleanup''}"' -Force - $CleanupTask = @" + $CleanupTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -9150,17 +9152,17 @@ Start-Sleep -Seconds 3 New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTask -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTaskPS -Encoding UTF8 -Force # Create vbs script that will help us calling Windows_Cleanup.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $CleanupTask = @" + $CleanupTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup.ps1", 0 "@ # Save in UTF8 without BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTask -Encoding Default -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTaskVBS -Encoding Default -Force # Create "Windows Cleanup" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -9182,7 +9184,7 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) # https://github.com/DCourtel/Windows_10_Focus_Assist/blob/master/FocusAssistLibrary/FocusAssistLib.cs # https://redplait.blogspot.com/2018/07/wnf-ids-from-perfntcdll-adk-version.html - $ToastNotification = @" + $ToastNotificationPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -9300,18 +9302,19 @@ while ([WinAPI.Focus]::GetFocusAssistState() -ne "OFF") "@ # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotification -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotificationPS -Encoding UTF8 -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding UTF8).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding UTF8 -Force # Create vbs script that will help us calling Windows_Cleanup_Notification.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $ToastNotification = @" + $ToastNotificationVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotification -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotificationVBS -Encoding Default -Force # Create the "Windows Cleanup Notification" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -9505,7 +9508,7 @@ function SoftwareDistributionTask # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) # https://github.com/DCourtel/Windows_10_Focus_Assist/blob/master/FocusAssistLibrary/FocusAssistLib.cs # https://redplait.blogspot.com/2018/07/wnf-ids-from-perfntcdll-adk-version.html - $SoftwareDistributionTask = @" + $SoftwareDistributionTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -9623,18 +9626,19 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Value $SoftwareDistributionTask -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Value $SoftwareDistributionTaskPS -Encoding UTF8 -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Encoding UTF8).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Encoding UTF8 -Force # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $SoftwareDistributionTask = @" + $SoftwareDistributionTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\SoftwareDistributionTask.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTask -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTaskVBS -Encoding Default -Force # Create the "SoftwareDistribution" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -9815,7 +9819,7 @@ function TempTask # We have to call PowerShell script via another VBS script silently because VBS has appropriate feature to suppress console appearing (none of other workarounds work) # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) - $TempTask = @" + $TempTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -9946,18 +9950,19 @@ Remove-Item -Path `$Paths -Recurse -Force New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Value $TempTask -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Value $TempTaskPS -Encoding UTF8 -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Encoding UTF8).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Encoding UTF8 -Force # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $TempTask = @" + $TempTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\TempTask.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTask -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTaskVBS -Encoding Default -Force # Create the "Temp" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method diff --git a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 index 2450f30c..842d8a0d 100644 --- a/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_LTSC_2021/Module/Sophia.psm1 @@ -812,6 +812,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); $hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData} } } + # Save in UTF8 without BOM $hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts" @@ -1139,6 +1140,7 @@ $($Type):$($Value)`n $Path = "$env:TEMP\User.txt" } + # Save in UTF8 without BOM Add-Content -Path $Path -Value $Policy -Encoding Default -Force } #endregion Additional function @@ -10248,7 +10250,7 @@ function CleanupTask # 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\'' -TaskName ''Windows Cleanup''}"' -Force - $CleanupTask = @" + $CleanupTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -10283,17 +10285,17 @@ Start-Sleep -Seconds 3 New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTask -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTaskPS -Encoding UTF8 -Force # Create vbs script that will help us calling Windows_Cleanup.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $CleanupTask = @" + $CleanupTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup.ps1", 0 "@ # Save in UTF8 without BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTask -Encoding Default -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTaskVBS -Encoding Default -Force # Create "Windows Cleanup" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -10315,7 +10317,7 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) # https://github.com/DCourtel/Windows_10_Focus_Assist/blob/master/FocusAssistLibrary/FocusAssistLib.cs # https://redplait.blogspot.com/2018/07/wnf-ids-from-perfntcdll-adk-version.html - $ToastNotification = @" + $ToastNotificationPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -10433,18 +10435,19 @@ while ([WinAPI.Focus]::GetFocusAssistState() -ne "OFF") "@ # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotification -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotificationPS -Encoding UTF8 -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding UTF8).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding UTF8 -Force # Create vbs script that will help us calling Windows_Cleanup_Notification.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $ToastNotification = @" + $ToastNotificationVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotification -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotificationVBS -Encoding Default -Force # Create the "Windows Cleanup Notification" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -10638,7 +10641,7 @@ function SoftwareDistributionTask # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) # https://github.com/DCourtel/Windows_10_Focus_Assist/blob/master/FocusAssistLibrary/FocusAssistLib.cs # https://redplait.blogspot.com/2018/07/wnf-ids-from-perfntcdll-adk-version.html - $SoftwareDistributionTask = @" + $SoftwareDistributionTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -10756,18 +10759,19 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Value $SoftwareDistributionTask -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Value $SoftwareDistributionTaskPS -Encoding UTF8 -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Encoding UTF8).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Encoding UTF8 -Force # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $SoftwareDistributionTask = @" + $SoftwareDistributionTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\SoftwareDistributionTask.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTask -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTaskVBS -Encoding Default -Force # Create the "SoftwareDistribution" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -10948,7 +10952,7 @@ function TempTask # We have to call PowerShell script via another VBS script silently because VBS has appropriate feature to suppress console appearing (none of other workarounds work) # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) - $TempTask = @" + $TempTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -11079,18 +11083,19 @@ Remove-Item -Path `$Paths -Recurse -Force New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Value $TempTask -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Value $TempTaskPS -Encoding UTF8 -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Encoding UTF8).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Encoding UTF8 -Force # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $TempTask = @" + $TempTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\TempTask.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTask -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTaskVBS -Encoding Default -Force # Create the "Temp" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method diff --git a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 index 8199c77c..b71bfba1 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 @@ -846,7 +846,8 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); $hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData} } } - $hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force + # Save in UTF8 without BOM + $hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding utf8NoBOM -Force Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts" } @@ -1173,7 +1174,8 @@ $($Type):$($Value)`n $Path = "$env:TEMP\User.txt" } - Add-Content -Path $Path -Value $Policy -Encoding Default -Force + # Save in UTF8 without BOM + Add-Content -Path $Path -Value $Policy -Encoding utf8NoBOM -Force } #endregion Additional function @@ -4939,11 +4941,11 @@ function Cursors # Reload cursor on-the-fly $Signature = @{ - Namespace = "WinAPI" - Name = "Cursor" - Language = "CSharp" - CompilerOptions = $CompilerOptions - MemberDefinition = @" + Namespace = "WinAPI" + Name = "Cursor" + Language = "CSharp" + CompilerOptions = $CompilerOptions + MemberDefinition = @" [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")] public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, uint pvParam, uint fWinIni); "@ @@ -9732,7 +9734,7 @@ function Export-Associations $AllJSON = @() $AppxProgIds = @((Get-ChildItem -Path "Registry::HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\PackageRepository\Extensions\ProgIDs").PSChildName) - [xml]$XML = Get-Content -Path "$env:TEMP\Application_Associations.xml" -Encoding UTF8 -Force + [xml]$XML = Get-Content -Path "$env:TEMP\Application_Associations.xml" -Encoding utf8 -Force $XML.DefaultAssociations.Association | ForEach-Object -Process { if ($AppxProgIds -contains $_.ProgId) { @@ -9926,7 +9928,7 @@ function Import-Associations try { - $JSON = Get-Content -Path $OpenFileDialog.FileName -Encoding UTF8 -Force | ConvertFrom-JSON + $JSON = Get-Content -Path $OpenFileDialog.FileName -Encoding utf8 -Force | ConvertFrom-JSON } catch [System.Exception] { @@ -12277,7 +12279,7 @@ function CleanupTask # 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\'' -TaskName ''Windows Cleanup''}"' -Force - $CleanupTask = @" + $CleanupTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -12312,17 +12314,17 @@ Start-Sleep -Seconds 3 New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTask -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTaskPS -Encoding utf8BOM -Force # Create vbs script that will help us calling Windows_Cleanup.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $CleanupTask = @" + $CleanupTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup.ps1", 0 "@ # Save in UTF8 without BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTask -Encoding utf8NoBOM -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTaskVBS -Encoding utf8NoBOM -Force # Create "Windows Cleanup" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -12344,7 +12346,7 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) # https://github.com/DCourtel/Windows_10_Focus_Assist/blob/master/FocusAssistLibrary/FocusAssistLib.cs # https://redplait.blogspot.com/2018/07/wnf-ids-from-perfntcdll-adk-version.html - $ToastNotification = @" + $ToastNotificationPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -12462,18 +12464,19 @@ while ([WinAPI.Focus]::GetFocusAssistState() -ne "OFF") "@ # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotification -Encoding utf8BOM -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotificationPS -Encoding utf8BOM -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding utf8BOM).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding utf8BOM -Force # Create vbs script that will help us calling Windows_Cleanup_Notification.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $ToastNotification = @" + $ToastNotificationVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotification -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotificationVBS -Encoding utf8NoBOM -Force # Create the "Windows Cleanup Notification" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -12667,7 +12670,7 @@ function SoftwareDistributionTask # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) # https://github.com/DCourtel/Windows_10_Focus_Assist/blob/master/FocusAssistLibrary/FocusAssistLib.cs # https://redplait.blogspot.com/2018/07/wnf-ids-from-perfntcdll-adk-version.html - $SoftwareDistributionTask = @" + $SoftwareDistributionTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -12785,18 +12788,19 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Value $SoftwareDistributionTask -Encoding utf8BOM -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Value $SoftwareDistributionTaskPS -Encoding utf8BOM -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Encoding utf8BOM).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Encoding utf8BOM -Force # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $SoftwareDistributionTask = @" + $SoftwareDistributionTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\SoftwareDistributionTask.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTask -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTaskVBS -Encoding utf8NoBOM -Force # Create the "SoftwareDistribution" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -12977,7 +12981,7 @@ function TempTask # We have to call PowerShell script via another VBS script silently because VBS has appropriate feature to suppress console appearing (none of other workarounds work) # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) - $TempTask = @" + $TempTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -13108,18 +13112,19 @@ Remove-Item -Path `$Paths -Recurse -Force New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Value $TempTask -Encoding utf8BOM -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Value $TempTaskPS -Encoding utf8BOM -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Encoding utf8BOM).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Encoding utf8BOM -Force # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $TempTask = @" + $TempTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\TempTask.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTask -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTaskVBS -Encoding utf8NoBOM -Force # Create the "Temp" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method diff --git a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 index 77c5365e..033b5381 100644 --- a/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11/Module/Sophia.psm1 @@ -816,6 +816,7 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); $hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData} } } + # Save in UTF8 without BOM $hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts" @@ -1143,6 +1144,7 @@ $($Type):$($Value)`n $Path = "$env:TEMP\User.txt" } + # Save in UTF8 without BOM Add-Content -Path $Path -Value $Policy -Encoding Default -Force } #endregion Additional function @@ -11496,7 +11498,7 @@ function CleanupTask # 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\'' -TaskName ''Windows Cleanup''}"' -Force - $CleanupTask = @" + $CleanupTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -11531,17 +11533,17 @@ Start-Sleep -Seconds 3 New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTask -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTaskPS -Encoding UTF8 -Force # Create vbs script that will help us calling Windows_Cleanup.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $CleanupTask = @" + $CleanupTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup.ps1", 0 "@ # Save in UTF8 without BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTask -Encoding Default -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTaskVBS -Encoding Default -Force # Create "Windows Cleanup" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -11563,7 +11565,7 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) # https://github.com/DCourtel/Windows_10_Focus_Assist/blob/master/FocusAssistLibrary/FocusAssistLib.cs # https://redplait.blogspot.com/2018/07/wnf-ids-from-perfntcdll-adk-version.html - $ToastNotification = @" + $ToastNotificationPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -11681,18 +11683,19 @@ while ([WinAPI.Focus]::GetFocusAssistState() -ne "OFF") "@ # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotification -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotificationPS -Encoding UTF8 -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding UTF8).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding UTF8 -Force # Create vbs script that will help us calling Windows_Cleanup_Notification.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $ToastNotification = @" + $ToastNotificationVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotification -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotificationVBS -Encoding Default -Force # Create the "Windows Cleanup Notification" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -11886,7 +11889,7 @@ function SoftwareDistributionTask # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) # https://github.com/DCourtel/Windows_10_Focus_Assist/blob/master/FocusAssistLibrary/FocusAssistLib.cs # https://redplait.blogspot.com/2018/07/wnf-ids-from-perfntcdll-adk-version.html - $SoftwareDistributionTask = @" + $SoftwareDistributionTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -12004,18 +12007,19 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Value $SoftwareDistributionTask -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Value $SoftwareDistributionTaskPS -Encoding UTF8 -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Encoding UTF8).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Encoding UTF8 -Force # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $SoftwareDistributionTask = @" + $SoftwareDistributionTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\SoftwareDistributionTask.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTask -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTaskVBS -Encoding Default -Force # Create the "SoftwareDistribution" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -12196,7 +12200,7 @@ function TempTask # We have to call PowerShell script via another VBS script silently because VBS has appropriate feature to suppress console appearing (none of other workarounds work) # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) - $TempTask = @" + $TempTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -12327,18 +12331,19 @@ Remove-Item -Path `$Paths -Recurse -Force New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Value $TempTask -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Value $TempTaskPS -Encoding UTF8 -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Encoding UTF8).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Encoding UTF8 -Force # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $TempTask = @" + $TempTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\TempTask.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTask -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTaskVBS -Encoding Default -Force # Create the "Temp" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method diff --git a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 index 7cb8465c..429c8d05 100644 --- a/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_11_PowerShell_7/Module/Sophia.psm1 @@ -820,7 +820,8 @@ public static extern bool SetForegroundWindow(IntPtr hWnd); $hosts = $hosts | Where-Object -FilterScript {$_ -notmatch $hostsData} } } - $hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding Default -Force + # Save in UTF8 without BOM + $hosts | Set-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Encoding utf8NoBOM -Force Start-Process -FilePath notepad.exe "$env:SystemRoot\System32\drivers\etc\hosts" } @@ -1147,7 +1148,8 @@ $($Type):$($Value)`n $Path = "$env:TEMP\User.txt" } - Add-Content -Path $Path -Value $Policy -Encoding Default -Force + # Save in UTF8 without BOM + Add-Content -Path $Path -Value $Policy -Encoding utf8NoBOM -Force } #endregion Additional function @@ -11512,7 +11514,7 @@ function CleanupTask # 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\'' -TaskName ''Windows Cleanup''}"' -Force - $CleanupTask = @" + $CleanupTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -11547,17 +11549,17 @@ Start-Sleep -Seconds 3 New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTask -Encoding UTF8 -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.ps1" -Value $CleanupTaskPS -Encoding utf8BOM -Force # Create vbs script that will help us calling Windows_Cleanup.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $CleanupTask = @" + $CleanupTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup.ps1", 0 "@ # Save in UTF8 without BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTask -Encoding utf8NoBOM -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup.vbs" -Value $CleanupTaskVBS -Encoding utf8NoBOM -Force # Create "Windows Cleanup" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -11579,7 +11581,7 @@ CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoPro # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) # https://github.com/DCourtel/Windows_10_Focus_Assist/blob/master/FocusAssistLibrary/FocusAssistLib.cs # https://redplait.blogspot.com/2018/07/wnf-ids-from-perfntcdll-adk-version.html - $ToastNotification = @" + $ToastNotificationPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -11697,18 +11699,19 @@ while ([WinAPI.Focus]::GetFocusAssistState() -ne "OFF") "@ # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotification -Encoding utf8BOM -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Value $ToastNotificationPS -Encoding utf8BOM -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding utf8BOM).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1" -Encoding utf8BOM -Force # Create vbs script that will help us calling Windows_Cleanup_Notification.ps1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $ToastNotification = @" + $ToastNotificationVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\Windows_Cleanup_Notification.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotification -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\Windows_Cleanup_Notification.vbs" -Value $ToastNotificationVBS -Encoding utf8NoBOM -Force # Create the "Windows Cleanup Notification" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -11902,7 +11905,7 @@ function SoftwareDistributionTask # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) # https://github.com/DCourtel/Windows_10_Focus_Assist/blob/master/FocusAssistLibrary/FocusAssistLib.cs # https://redplait.blogspot.com/2018/07/wnf-ids-from-perfntcdll-adk-version.html - $SoftwareDistributionTask = @" + $SoftwareDistributionTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -12020,18 +12023,19 @@ Get-ChildItem -Path `$env:SystemRoot\SoftwareDistribution\Download -Recurse -For New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Value $SoftwareDistributionTask -Encoding utf8BOM -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Value $SoftwareDistributionTaskPS -Encoding utf8BOM -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Encoding utf8BOM).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.ps1" -Encoding utf8BOM -Force # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $SoftwareDistributionTask = @" + $SoftwareDistributionTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\SoftwareDistributionTask.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTask -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\SoftwareDistributionTask.vbs" -Value $SoftwareDistributionTaskVBS -Encoding utf8NoBOM -Force # Create the "SoftwareDistribution" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -12212,7 +12216,7 @@ function TempTask # We have to call PowerShell script via another VBS script silently because VBS has appropriate feature to suppress console appearing (none of other workarounds work) # powershell.exe process wakes up system anyway even from turned on Focus Assist mode (not a notification toast) - $TempTask = @" + $TempTaskPS = @" # https://github.com/farag2/Sophia-Script-for-Windows # https://t.me/sophia_chat @@ -12343,18 +12347,19 @@ Remove-Item -Path `$Paths -Recurse -Force New-Item -Path $env:SystemRoot\System32\Tasks\Sophia -ItemType Directory -Force } # Save in UTF8 with BOM - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Value $TempTask -Encoding utf8BOM -Force + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Value $TempTaskPS -Encoding utf8BOM -Force # Replace here-string double quotes with single ones (Get-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Encoding utf8BOM).Replace('@""', '@"').Replace('""@', '"@') | Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.ps1" -Encoding utf8BOM -Force # Create vbs script that will help us calling PS1 script silently, without interrupting system from Focus Assist mode turned on, when a powershell.exe console pops up - $TempTask = @" + $TempTaskVBS = @" ' https://github.com/farag2/Sophia-Script-for-Windows ' https://t.me/sophia_chat CreateObject("Wscript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden -File %SystemRoot%\System32\Tasks\Sophia\TempTask.ps1", 0 "@ - Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTask -Encoding Default -Force + # Save in UTF8 without BOM + Set-Content -Path "$env:SystemRoot\System32\Tasks\Sophia\TempTask.vbs" -Value $TempTaskVBS -Encoding utf8NoBOM -Force # Create the "Temp" task # We cannot create a schedule task if %COMPUTERNAME% is equal to %USERNAME%, so we have to use a "$env:COMPUTERNAME\$env:USERNAME" method @@ -13858,7 +13863,7 @@ function OpenWindowsTerminalAdminContext try { - $Terminal = Get-Content -Path "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json" -Encoding UTF8 -Force | ConvertFrom-Json + $Terminal = Get-Content -Path "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json" -Encoding utf8 -Force | ConvertFrom-Json } catch [System.ArgumentException] { @@ -13903,7 +13908,7 @@ function OpenWindowsTerminalAdminContext } # Save in UTF-8 with BOM despite JSON must not has the BOM: https://datatracker.ietf.org/doc/html/rfc8259#section-8.1. Unless Terminal profile names which contains non-Latin characters will have "?" instead of titles - ConvertTo-Json -InputObject $Terminal -Depth 4 | Set-Content -Path "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json" -Encoding UTF8 -Force + ConvertTo-Json -InputObject $Terminal -Depth 4 | Set-Content -Path "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json" -Encoding utf8BOM -Force } #endregion Context menu