Last active
August 29, 2023 16:54
-
-
Save oznotes/d9c7572ae1d157583d3c68ecdd473581 to your computer and use it in GitHub Desktop.
Add Folder to Defender Exclusion C# .NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Collections.ObjectModel; | |
using System.Management.Automation; | |
// Add Folder to Defender Exclusion running powershell script with-in C# .NET | |
namespace helper | |
{ | |
class Program | |
{ | |
// run the software with administrator rights | |
// app.manifest | |
// <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> | |
static void Main() | |
{ | |
using (PowerShell PowerShellInst = PowerShell.Create()) | |
{ | |
// Get the Folder Path. | |
string path = Directory.GetCurrentDirectory(); | |
PowerShellInst.AddScript(@"Add-MpPreference -ExclusionPath '" + path + "'"); | |
Collection<PSObject> PSOutput = PowerShellInst.Invoke(); | |
Console.WriteLine(path+" to Windows Defender [added][+]"); | |
Console.Read(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will prevent a console window from showing up, but it will still allow your application to run.