Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone, I want to put a path in the windows registry, but I haven't been able to do it. That's how I want to add a folder to Windows Defender exclusion.
Please where am I wrong and what is the problem? I am asking for your help. Thank you.

What I have tried:

C#
private void setFolderPath() 
        {
            try
            {               
                Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Defender\\Exclusions\\Paths", @"C:\New folder", 0);
            }
            catch
            {
            }
        }
Posted
Updated 10-Sep-22 5:11am
v2

You cannot add entries to HKEY_LOCAL_MACHINE unless you are running with administrator privilege. But it would be much easier just to use Windows Defender to do it for you: Access the Microsoft Defender for Endpoint APIs | Microsoft Docs[^].
 
Share this answer
 
First off, don't discard exceptions: if you catch an exception and don't access the Exception Object, you discard the information that helps you work out what the problem is!

In this case, it's an access exception.

You cannot access some of the registry without an elevated app - and that includes everything under the LOCAL_MACHINE branch. Which means UAC and user input for security reasons.

And what did you expect? If you could access the whitelist without UAC then so could any other app - which would render the AV software useless.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900