Skip to content

Commit 0b49448

Browse files
authored
add update cleanup check #179
1 parent 98f5b75 commit 0b49448

2 files changed

Lines changed: 86 additions & 2 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ The current 25H2 build of Windows 11 and future builds will include increasingly
4040
- **Disable Rewrite AI Feature in Notepad**
4141
- **Remove Recall Tasks**
4242
- Forcibly removes all instances of Recall's scheduled tasks
43+
- **Update Cleanup Check**
44+
- Creates scheduled task to check if Windows has been updated and if it has, newly installed AI features will be removed
4345

4446
- #### Install Classic Apps
4547
- These options will allow you to replace the modern AI infested apps with their classic version
@@ -115,6 +117,7 @@ RemoveAIFiles
115117
HideAIComponents
116118
DisableRewrite
117119
RemoveRecallTasks
120+
UpdateCleanupCheck
118121
```
119122

120123
**Run Install Classic Apps**

RemoveWindowsAi.ps1

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ param(
1010
'RemoveAIFiles',
1111
'HideAIComponents',
1212
'DisableRewrite',
13-
'RemoveRecallTasks')]
13+
'RemoveRecallTasks',
14+
'UpdateCleanupCheck')]
1415
[array]$Options,
1516
[switch]$AllOptions,
1617
[switch]$revertMode,
@@ -2570,6 +2571,81 @@ Get-ScheduledTask -TaskName "*Office Actions Server*" -ErrorAction SilentlyConti
25702571

25712572
}
25722573

2574+
2575+
2576+
function Update-Cleanup-Check {
2577+
2578+
if (!$revert) {
2579+
#fastest method to get majorbuild.updateBuildRevision ex. 26200.7922
2580+
$key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion')
2581+
$OSBuild = "$($key.GetValue('CurrentBuild')).$($key.GetValue('UBR'))"
2582+
$key.Close()
2583+
#attempt to get cached build incase user has already cached one before but is no longer accurate somehow
2584+
try {
2585+
$key2 = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey('SOFTWARE\RemoveWindowsAI')
2586+
$CurrentCachedBuild = "$($key2.GetValue('CachedBuild'))"
2587+
$key2.Close()
2588+
}
2589+
catch {
2590+
$CurrentCachedBuild = $null
2591+
}
2592+
2593+
#cache current build before making update script in regitry if the script detects and update as happened the cachedbuild value will be updated
2594+
$regValName = 'CachedBuild'
2595+
if ($CurrentCachedBuild -ne $OSBuild) {
2596+
Write-Status -msg 'Caching Current OS Build in Registry...'
2597+
Reg.exe add 'HKLM\SOFTWARE\RemoveWindowsAI' /v $regValName /d "$OSBuild" /t REG_SZ /f >$null
2598+
}
2599+
2600+
#grab update cleanup script from github instead of embedding it in here
2601+
try {
2602+
Write-Status -msg 'Attempting to get Update Cleanup script from Github...'
2603+
$scriptContent = Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/zoicware/RemoveWindowsAI/refs/heads/main/RemoveAI-UpdateCleanup.ps1' -UseBasicParsing -ErrorAction Stop | Select-Object Content
2604+
}
2605+
catch {
2606+
Write-Status -msg 'Unable to get Update Cleanup script from Github!' -errorOutput
2607+
return
2608+
}
2609+
2610+
#create script
2611+
$scriptPath = "$env:ProgramData\RemoveAI-UpdateCleanup.ps1"
2612+
Set-Content -Path $scriptPath -Value $scriptContent.Content -Force
2613+
2614+
#create silent script so that there is no powershell window flash for the user
2615+
$vbsScriptContent = @"
2616+
Dim shell,command
2617+
command = "powershell.exe -ep bypass -c ""$env:ProgramData\RemoveAI-UpdateCleanup.ps1"""
2618+
Set shell = CreateObject("WScript.Shell")
2619+
shell.Run command,0
2620+
"@
2621+
$vbsPath = "$env:ProgramData\RemoveAI-UpdateCleanup-Silent.vbs"
2622+
Set-Content -Path $vbsPath -Value $vbsScriptContent -Force
2623+
2624+
Write-Status -msg 'Creating Update Cleanup Scheduled Task...'
2625+
$userSid = (Get-LocalUser -Name $env:USERNAME).SID.Value
2626+
$action = New-ScheduledTaskAction -Execute 'wscript.exe' -Argument "$env:ProgramData\RemoveAI-UpdateCleanup-Silent.vbs"
2627+
$trigger = New-ScheduledTaskTrigger -AtLogOn
2628+
$principal = New-ScheduledTaskPrincipal -UserId $userSid -LogonType ServiceAccount -RunLevel Highest
2629+
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
2630+
#create update cleanup checker task
2631+
Register-ScheduledTask -TaskName 'RemoveAI-UpdateCleanupChecker' -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force | Out-Null
2632+
2633+
}
2634+
else {
2635+
Write-Status -msg 'Removing Update Cleanup Script and Task...'
2636+
Unregister-ScheduledTask -TaskName 'RemoveAI-UpdateCleanupChecker' -Confirm:$false -ErrorAction SilentlyContinue
2637+
Remove-Item "$env:ProgramData\RemoveAI-UpdateCleanup-Silent.vbs" -ErrorAction SilentlyContinue -Force
2638+
Remove-Item "$env:ProgramData\RemoveAI-UpdateCleanup.ps1" -ErrorAction SilentlyContinue -Force
2639+
}
2640+
2641+
2642+
}
2643+
2644+
#===============================================================================================================================
2645+
#
2646+
# CLASSIC APP INSTALL FUNCTIONS
2647+
#
2648+
#===============================================================================================================================
25732649
function install-photoviewer {
25742650

25752651
#restore classic photoviewer
@@ -2970,6 +3046,7 @@ if ($nonInteractive) {
29703046
Hide-AI-Components
29713047
Disable-Notepad-Rewrite
29723048
Remove-Recall-Tasks
3049+
Update-Cleanup-Check
29733050
}
29743051
else {
29753052
#loop through options array and run desired tweaks
@@ -2984,6 +3061,7 @@ if ($nonInteractive) {
29843061
'HideAIComponents' { Hide-AI-Components }
29853062
'DisableRewrite' { Disable-Notepad-Rewrite }
29863063
'RemoveRecallTasks' { Remove-Recall-Tasks }
3064+
'UpdateCleanupCheck' { Update-Cleanup-Check }
29873065
}
29883066
}
29893067

@@ -3010,6 +3088,7 @@ else {
30103088
'Hide-AI-Components' = 'Hides AI components in Windows Settings by modifying the SettingsPageVisibility policy to prevent user access to AI settings.'
30113089
'Disable-Notepad-Rewrite' = 'Disables the AI Rewrite feature in Windows Notepad through registry modifications and group policy settings.'
30123090
'Remove-Recall-Tasks' = 'Removes Recall-related scheduled tasks from the Windows Task Scheduler to prevent AI data collection processes from running.'
3091+
'Update-Cleanup-Check' = 'Creates a silent scheduled task to run at log-on to check if Windows has been updated... if it has then the script will cleanup newly installed AI features'
30133092
}
30143093

30153094
$window = New-Object System.Windows.Window
@@ -3146,7 +3225,8 @@ else {
31463225
'Remove-AI-Files'
31473226
'Hide-AI-Components'
31483227
'Disable-Notepad-Rewrite'
3149-
'Remove-Recall-Tasks'
3228+
'Remove-Recall-Tasks'
3229+
'Update-Cleanup-Check'
31503230
)
31513231

31523232
foreach ($func in $functions) {
@@ -3809,6 +3889,7 @@ else {
38093889
'Hide-AI-Components' { Hide-AI-Components }
38103890
'Disable-Notepad-Rewrite' { Disable-Notepad-Rewrite }
38113891
'Remove-Recall-Tasks' { Remove-Recall-Tasks }
3892+
'Update-Cleanup-Check' { Update-Cleanup-Check }
38123893
'Install-Classic-Photoviewer' { install-classicapps -app 'photoviewer' }
38133894
'Install-Classic-Mspaint' { install-classicapps -app 'mspaint' }
38143895
'Install-Classic-SnippingTool' { install-classicapps -app 'snippingtool' }

0 commit comments

Comments
 (0)