How to add folder exclusion to windows defender in context menu?

Page 1 of 2 12 LastLast

  1. yxq
    Posts : 18
    Windows 10
       #1

    How to add folder exclusion to windows defender in context menu?


    I want to add the folder exclusion to windows defender in the context menu of folder in Registry
    add exclusion to windows defender from command line code example | Newbedev

    powershell -Command Add-MpPreference -ExclusionPath "%1" ,but it seem not work.
      My Computer


  2. Posts : 4,594
    Windows 10 Pro
       #2

    Wouldn`t it be simpler to add exclusions to Windows Security Center ?
      My Computers


  3. Posts : 6,247
    Windows 11 Pro - Windows 7 HP - Lubuntu
       #3

    AddRAM said:
    Wouldn`t it be simpler to add exclusions to Windows Security Center ?

    - Go to Start > Settings > Update & Security > Windows Security > Virus & threat protection.
    - Underder Virus & threat protection settings, select Manage settings, and then under Exclusions, select Add or remove exclusions.
    -Select Add an exclusion, and then select from files, folders, file types, or process. A folder exclusion will apply to all subfolders within the folder as well.
      My Computers


  4. yxq
    Posts : 18
    Windows 10
    Thread Starter
       #4

    I known how to add the exclusion folders in Settings, i only want to add it to the context menu when right-click the folders. thank you.
      My Computer


  5. Posts : 4,594
    Windows 10 Pro
       #5

    OK, I`m sure someone will be along to help you with that
      My Computers


  6. Posts : 3,272
    Win10
       #6

    The problem is that, that PS command has to be run elevated, and using the command through the Registry context menu setting doesn't do so.

    eg. entering this as a command in the Registry will show the error
    "Add-MpPreference : You don't have enough permissions to perform the requested operation."
    Code:
    Powershell.exe -ExecutionPolicy Bypass -NoProfile -NoExit -command "& {Add-MpPreference -ExclusionPath \"%1\"}"
    One way would be by using third party apps which are able to work through the context menu eg.
    Defender Exclusion Tool v1.3

    Otherwise, if you are only after something simple, you may be able to do it using a combination of a .bat file together with a .ps1 file, where both the script files are saved in the Windows "Send to" folder, and seems to work. This would enable the Powershell script with the relevant command to run elevated against selected folder/s in Explorer.
      My Computers


  7. Posts : 16,784
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #7

    I suggest you
    1 Test the script [in a PS1 file] well so you know you have got it right. Drag'n'drop folders/files onto it to test the %1 part of the script.
    2 Create a shortcut to the script and set it to run elevated. Since it's a shortcut to a PS script, make it in the normal way then add powershell.exe to the start of its Target field.
    3 Copy the shortcut [not the script] to SendTo - %userprofile%\AppData\Roaming\Microsoft\Windows\SendTo
    4 Repeat this for any other user accounts.

    This is not what you asked for. To get any further you'd need to set up a Task scheduler task to run the script elevated then write a companion script that runs the TS task and put that companion script into your context menu instead of the one you originally intended.

    Denis
      My Computer


  8. Posts : 3,272
    Win10
       #8

    Using the alternative method suggested by Denis.

    Save the script shown below as "Defender_Add_Exclusion.ps1" in a safe folder.
    Create a Shortcut to it and add the following to the beginning of the path in the "Target box" so it reads something like this (depending on the location of the .ps1 file, eg. mine is located in C:\myscripts1\)
    Code:
    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoProfile -NoExit -file "C:\myscripts1\Defender_Add_Exclusion.ps1"
    Change the "Advanced" property of the Shortcut to "Run as administrator", and move it to the "Send to" folder located at Shell:Sendto

    Contents of
    Defender_Add_Exclusion.ps1
    Code:
    ForEach ($arg in $args) {
    Powershell.exe -ExecutionPolicy Bypass -NoProfile -command "& {Add-MpPreference -ExclusionPath `'$arg'; Write-Host Add-MpPreference -ExclusionPath `'$arg' }" 
    }
    pause
    stop-process -Id $PID
    It should work as shown.
    How to add folder exclusion to windows defender in context menu?-defender_add_exclusion1a.pngHow to add folder exclusion to windows defender in context menu?-defender_add_exclusion1b.pngHow to add folder exclusion to windows defender in context menu?-defender_add_exclusion1c.png
    Last edited by das10; 08 Jan 2022 at 07:24.
      My Computers


  9. Posts : 16,784
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #9

    Try3 said:
    2 Create a shortcut to the script and set it to run elevated. Since it's a shortcut to a PS script, make it in the normal way then add powershell.exe to the start of its Target field.
    And, when it's all tested and OK, you can alter the shortcut's Properties to run minimised.

    Denis
      My Computer


  10. yxq
    Posts : 18
    Windows 10
    Thread Starter
       #10

    I will test them, thank you.


    Sure, i will test them, thank you.
      My Computer


 

  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 17:05.
Find Us




Windows 10 Forums