My Computer
System One
-
- OS
- Windows 10/11
- Computer type
- Laptop
- Manufacturer/Model
- Acer
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
The tutorial worked!Clear Windows Security History
The above Tutorial may do it.
If is doesn't this will:
Code:<# : batch script @echo off powershell -nop "if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) { Start-Process -Verb RunAs 'cmd.exe' -ArgumentList '/c %~dpnx0 %*' } else { Invoke-Expression ([System.IO.File]::ReadAllText('%~f0')) }" goto :eof #> # https://www.tiraniddo.dev/2019/09/the-art-of-becoming-trustedinstaller.html $ScriptBlock = { $MAPS_Status = (Get-MpPreference).MAPSReporting Set-MpPreference -DisableRealtimeMonitoring 1 Set-MpPreference -MAPSReporting Disabled Get-ChildItem -File 'C:\ProgramData\Microsoft\Windows Defender\Scans\History\Service' -Recurse | Remove-Item -Force Set-MpPreference -DisableRealtimeMonitoring 0 Set-MpPreference -MAPSReporting $MAPS_Status } # Create scheduled task $TaskName = 'Clear Defender Protection History' $SchedulerPath = '\Microsoft\Windows\PowerShell\ScheduledJobs' Unregister-ScheduledJob $TaskName -Confirm:$false 2>&1 | Out-Null Register-ScheduledJob -Name $TaskName -ScriptBlock $ScriptBlock | Out-Null $adminAccount = Get-LocalUser | Where-Object {$_.SID -like "*-500"} | Select-Object -ExpandProperty Name $Principal = New-ScheduledTaskPrincipal -UserId "$env:COMPUTERNAME\$adminAccount" Set-ScheduledTask -TaskPath $SchedulerPath -TaskName $TaskName -Principal $Principal | Out-Null $Service = New-Object -ComObject 'Schedule.Service' $Service.Connect() # Invoke task as TI $User = 'NT SERVICE\TrustedInstaller' $Folder = $Service.GetFolder($SchedulerPath) $Task = $Folder.GetTask($TaskName) $Task.RunEx($null, 0, 0, $User) | Out-Null # Wait for task completion, or timed out $Timeout = 60 $Timer = [Diagnostics.Stopwatch]::StartNew() while (((Get-ScheduledTask -TaskName $TaskName).State -ne 'Ready') -and ($Timer.Elapsed.TotalSeconds -lt $Timeout)) { Start-Sleep -Seconds 1 } $Timer.Stop() # Remove scheduled task Unregister-ScheduledJob $TaskName -Confirm:$false | Out-Null
Thanks but deleting the offending folder in Safe Mode worked.
I'll test it, i have to keep up my name...
Tested clean win 11 vm with:
Defender version; 4.18.24030.9-0
Windows 11 version: 23H2 OS build: 22631.3527
Works Like a Charm!
I wrote the other program.How did you figure out so fast how that that other program did it this way?
You will just get a console window flash if there is no Protection history to be cleared, but that would also be the case if you right-click and select "Run as Administrator". But it sounds like you're getting the reboot prompt when using "Run as Administrator", but not when double-clicking. Is that correct and is that consistent for all your machines?After running it on some more machines, i have noticed one more thing about the script.
If i double click the file, UAC elevation prompt comes up, then a black screen flashes.
So i guess, this part of the scrips fails, and hits the goto :eof and so skipping the rest of the script.
Right click and run as administrator works.
Yes, with right click run as admin, i get the reboot prompt, so the log file is detected.But it sounds like you're getting the reboot prompt when using "Run as Administrator", but not when double-clicking. Is that correct and is that consistent for all your machines?
I just retested on 23H2 with both Administrator and Standard users and it worked fine with just a double-click for me. There may be some setting on your machines that affects the script. @garlin is more familiar with the self-elevation code, so I hope he's available to chime in on possible causes.Yes, with right click run as admin, i get the reboot prompt, so the log file is detected.
All machines where i have run the script, where windows machines with the same 23H2 updates.
I will boot up later today, some old cloned machines that are update until jan/febr or even later. Do you also want to know it for windows 10?
I did this change, and after elevation, an empty command prompt was opened, no error shown.I think to debug what's happening for @Tester, we change -ArgumentList '/c %~dpnx0 %*' to '/k %~dpnx0 %*'.
No. Only the original ClearDefenderHistory.bat used TrustedInstaller. It stopped working for most of us recently. The current ClearDefenderHistory.cmd script that creates a task (and the previous version that created a RunOnce entry) only pop up a UAC prompt so that the script can run with Administrator level access. It should be the same as right-clicking and selecting "Run as Administrator".I know from tools that impersonate trusted installers etc. Like: RunAsTI64, ExecTI, Advanced Run x64, That two depency's are needed for those to run correctly.
Modules installer, and Secondary Login.
Any dependency's that i can check for this script?
Simply for the convenience.I'm impressed by all this sophisticated script writing but why don't you folks simply delete the Defender history folder at
C:\ProgramData\Microsoft\Windows Defender\Scans\History\Service using Safe Mode which still works?