Clear Windows Security Center (Defender) Protection History

Page 5 of 8 FirstFirst ... 34567 ... LastLast

  1. Posts : 776
    Windows 7
       #41

    PS commands for Defender require Admin rights to update any settings, but the script to clear Defender history needs the additional steps of removing a protected folder. That folder is owned by TrustedInstaller to prevent casual or malicious interference.

    If you only need to Set-MpPreference, then always check the title of your CMD, PowerShell or Terminal window has the word "Administrator".
      My Computer


  2. Posts : 31
    10 Pro
       #42

    Many thanks Les,
    I didn't see the UAC warning as I have have it permanently disabled. I have been a heavy PC user since 1989, and have never had a virus on my PCs. I object when Microsoft throws another required click in my way.

    I will need time to work through your link, Add Open PowerShell window here as administrator in Windows 10 , but I certainly will.

    When I realised that my right click option did not work, and I used the other option to open Admin Powershell, the command did remove my all my virus notifications. To recap, I was logged in Win11 as Administrator, then I used the alternate way of opening Powershell Admin, then the command "Set-MpPreference -QuarantinePurgeItemsAfterDelay 1" did work. I was not, as far as I know, wasn't in "TrustedInstaller" access mode.

    I'm not good interpreting your well explained ClearDefenderHistory-type script, but I could see that it does include the elevation to TrustedInstaller. Your script is beautifully written, and from previous issues I have had, it will be of immense help in many circumstances.

    And I will certainly be following up PowerRun, etc.

    Your help is very much appreciated and I thank you.

    Doug Price

    - - - Updated - - -

    Please be aware that with me being in Australia, your day and mine have very little overlap. Currently it is 0240 here. Hence my response may be delayed. I'm old and my functioning hours are a subset of1400 - 0400 in Aus time, in US central time that is, I think, 2100 - 1200 or there abouts???? I should know much better as I have worked in various places in the US in the past.
      My Computers


  3. Posts : 745
    Windows 10/11
       #43

    doug4901 said:
    I didn't see the UAC warning as I have have it permanently disabled.
    That will make it a little less clear that you're elevated, but, as @garlin mentioned, if it doesn't say "Administrator" in the window title, that would be the another clue that there's an issue.

    I will need time to work through your link, Add Open PowerShell window here as administrator in Windows 10, but I certainly will.
    The tutorials and scripts provided here by @Brink are excellent and reliable so you can count on them to just work or use them as a basis to make your own custom version.

    To recap, I was logged in Win11 as Administrator, then I used the alternate way of opening Powershell Admin, then the command "Set-MpPreference -QuarantinePurgeItemsAfterDelay 1" did work. I was not, as far as I know, wasn't in "TrustedInstaller" access mode.
    Yes, purging the quarantined items only requires standard elevation (i.e. Run as Administrator). Clearing the Defender history requires TrustedInstaller.

    I'm not good interpreting your well explained ClearDefenderHistory-type script, but I could see that it does include the elevation to TrustedInstaller. Your script is beautifully written, and from previous issues I have had, it will be of immense help in many circumstances.
    Actually, the script was written by @garlin, so all credit goes there. I just made a home for it in my GitHub pages.

    And I will certainly be following up PowerRun, etc.
    Yes, tools like that are great, but, of course, must be used with care. They are certainly much safer to use then messing around with permissions (when it comes to accessing things that require TrustedInstaller).
      My Computer


  4. Posts : 745
    Windows 10/11
       #44

    @garlin A couple of interesting observations today that perhaps you could shed more light on.

    First, as a matter of curiosity, I ran the code from the script block section of ClearDefenderHistory.bat in a PowerShell window (also tried a Cmd window) elevated to TrustedInstaller via PowerRun, but the code was not able to remove the history (lots of errors). I verified that I was indeed running as TrustedInstaller by creating a folder that was restricted to NT Service\TrustedInstaller. I checked by opening a Cmd window as SYSTEM and could not remove the folder. In the window opened as TrustedInstaller, I could remove the folder, so I was satisfied regarding access level. My only idea is that the script in ClearDefenderHistory.bat is running non-interactively and that makes a difference in regards to stopping real-time protection.

    Second, the original version of ClearDefenderHistory.bat (the one with the direct reference to "Administrator") is now being detected as malicious on my machine as of today and got quarantined. The new version (with the SID reference) continued to work fine without any bother from Defender. Weird.
      My Computer


  5. Posts : 776
    Windows 7
       #45

    I've seen subtle differences in what NSudo, PowerRun and TI scheduled tasks can perform because of how they each handle the security contexts. For example, NSudo can sometimes do something PowerRun can't do.

    To me, the question is what's the least intrusive tool for the given task: whether it's a sledgehammer (NSudo), chisel (PowerRun), or magic marker (PS -verb or TI task).

    I would suspect Defender is working off machine-learning heuristics, and "Administrator" is a clear keyword. But then you could probably fool the detection engine with $('Ad' + 'm' + 'inistr' + 'ator')...
      My Computer


  6. Posts : 130
    Win 10x64 Pro
       #46

    Just popping in to say, it works fine and Thank you.
      My Computers


  7. Posts : 10
    Windows 10 Pro
       #47

    garlin said:
    Run this script ClearDefenderHistory.bat to safely stop Defender protections, clear the history files, and restart protection. It's a wrapper to a PowerShell script that creates a temporary scheduled task, and runs as TrustedInstaller.

    Attachment 395284

    This is a much better approach than taking ownership of Defender folders, which is a security hole since if you can delete files, so does malware running as you. The script waits for the task to complete (or times out), and removes the task. If you're not already Administrator, it will ask for permissions.
    Amazing script!!! Worked like a charm!

    (NOTE: The folders under C:\ProgramData\Microsoft\Windows Defender\Scans\History\Service\DetectionHistory were not removed, but that's about it!)
      My Computer


  8. Posts : 776
    Windows 7
       #48

    marcolopes said:
    (NOTE: The folders under C:\ProgramData\Microsoft\Windows Defender\Scans\History\Service\DetectionHistory were not removed, but that's about it!)
    There's no real need to remove any of those empty folders.

    Apps like Defender or any browser (Edge, Chrome, Firefox) will create what are known as "hash" folders. The idea is if you needed to keep track of new items, you sort them into "random" folders based on a calculated math value, instead of indexing them. This performs much faster for the app.

    The folders themselves have no real meaning, other than some future files might get stored there, or in another parallel subfolder that gets created as needed. Whether you remove the empty folders or not, doesn't change anything since Defender creates new ones as needed.

    If you wanted the folders removed, take out the (-File) in this line:
    Code:
    Get-ChildItem -File 'C:\ProgramData\Microsoft\Windows Defender\Scans\History\Service' -Recurse | Remove-Item -Force
      My Computer


  9. Posts : 10
    Windows 10 Pro
       #49

    garlin said:
    There's no real need to remove any of those empty folders.

    Apps like Defender or any browser (Edge, Chrome, Firefox) will create what are known as "hash" folders. The idea is if you needed to keep track of new items, you sort them into "random" folders based on a calculated math value, instead of indexing them. This performs much faster for the app.

    The folders themselves have no real meaning, other than some future files might get stored there, or in another parallel subfolder that gets created as needed. Whether you remove the empty folders or not, doesn't change anything since Defender creates new ones as needed.

    If you wanted the folders removed, take out the (-File) in this line:
    Code:
    Get-ChildItem -File 'C:\ProgramData\Microsoft\Windows Defender\Scans\History\Service' -Recurse | Remove-Item -Force
    Great explanation! Thanks!
      My Computer


  10. Posts : 130
    Win 10x64 Pro
       #50

    Hello, maybe the last time.

    Just popping in to report this script works fine on win 11 too. I finished rebuilding 1 of 2 PC and updated it to 11 (OMG the start menu is FUGLY) and have already used this script.

    Of all things Windows Defender was removing my GPU driver package Most likely because it was "repackaged" to remove all the bloat/spyware.

    Edition Windows 11 Pro
    Version 23H2
    Installed on ‎3/‎16/‎2024
    OS build 22631.3155
    Experience Windows Feature Experience Pack 1000.22684.1000.0
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 12:26.
Find Us




Windows 10 Forums