简体   繁体   中英

How to check a unit (C:) dirty bit using C#

I know it is possible to check the dirty bit status of a unit by running the command fsutil dirty query c: from an elevated prompt. On windows 10 it is also possible to know if C: dirty bit is set without the need of admin privileges simply going into the System and Maintenance page, if dirty bit is set there will be an advice telling it is necessary to reboot in order to repair a damage in the file sistem. How could the dirty bit status (of any unit or even only C:) be checked from a C# program?

Thanks in Advance to anyone will answer

You can get this information using a WMI query

var q = new ObjectQuery("Select * FROM Win32_Volume");
using (var searcher = new ManagementObjectSearcher(q))
using (var moc = searcher.Get())
{
    foreach (ManagementObject volume in moc)
    {
        String label = (String)volume["Label"];
        Boolean dirtyBitSet = (Boolean)(volume["DirtyBitSet"] ?? false);
        Console.WriteLine($"{label} => {dirtyBitSet}");
    }
}

You should add a reference to the System.Management assembly and also run your program using an elevated prompt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM