My application needs to insert itself into Windows Defender exclusions. Just create a MYapp.exe key on the path
{HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Defender\Exclusions\Processes}
, but it is returning the message stating that I do not have permission.
I am an administrator user of the machine and my application is running as an administrator but the error is the same.
Windows 8.1 and 10 have a command that can be executed by Power Shell, but Windows 7 does not. Can you help me?
Here is the code I'm using:
RegistryKey localRaiz;
RegistryKey key;
try
{
string path = @"SOFTWARE\Microsoft\Windows Defender\Exclusions\Processes";
localRaiz = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
key = localRaiz.OpenSubKey(path);
key.SetValue("MPI.exe", 0, RegistryValueKind.DWord);
key.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}