Search code examples
c#loggingdisksystem-administrationdriveinfo

Is there a way to disable the write behind caching policy on a disk drive programmatically using C# in windows?


I need to remove write behind caching on the disk drives of our servers. Doing so in windows ==> Device Manager ==> Disk Drives ==> (right click) Properties ==> Policies ==> (CheckBox) Enable write behind caching | is easy but windows re-enables it automatically. I believe this happens with updates.

I want to know if I can access these policies using C# to disable them on a daily basis.

Anyone know of a way?

I have looked at DriveInfo but found no methods to access the policies.


Solution

  • Okay, So I found a solution for this issue.

    As OlivierRogier also mentioned. This setting seems to be stored in the Registry under:

    HKLM\SYSTEM\CurrentControlSet\Enum\(IDE OR SCSI)\Diskxxxxxxxxxxxx\DeviceParameters\Disk Key : UserWriteCacheSetting where xxxxxxx is manufacturer information.

    Link HERE

    I set up some code that checks this setting on a daily basis => changes it => restarts the computer. Will share the code if requested.

    Thank you everyone for your input. Blixem