In my Asp.Net Core MVC Web Application I need to know if the Write Filter (UWF) is enabled or not.
I'm currently working on Windows 10 Enterprise.
After googling a lot I found that it could be done by accessing Windows Management Instrumentation (WMI). Unlike Asp.Net, Asp.Net Core needs an external library called ORMi in order to work with WMI.
Despite having read the Microsoft Documentation I couldn't understand how to make the things work... I'll leave you the documentation I used:
How you guys could help me. Thanks!
I've found the solution.
First you need to install the write filter: Here's the guide
Then you need to install the ORMi NuGet Packet in Visual Studio.
Have a look to this website to have a better understanting about WMI.
I'll leave you the code I wrote
[WMIClass("UWF_Filter")]
public class UnifiedWriteFilter : WMIInstance
{
[WMIProperty("CurrentEnabled")]
public bool IsEnabled { get; set; }
}
public void IsWriteFilterEnabled()
{
WMIHelper helper = new WMIHelper("root\\standardcimv2\\embedded");
UnifiedWriteFilter unifiedWriteFilter = helper.QueryFirstOrDefault<UnifiedWriteFilter>(); // The query is correct
if (unifiedWriteFilter.IsEnabled)
{
Console.WriteLine("Write filter Enabled");
ViewBag.WriteFilterStatus = "enabled";
}
else
{
Console.WriteLine("Write filter Not Enabled");
ViewBag.WriteFilterStatus = "disabled";
}
}