3

According to Microsoft, in Windows 10/8/7, to Turn Disk Write Caching On or Off:

  1. Right-click My Computer, and then click Properties.
  2. Click the Hardware tab, and then click Device Manager.
  3. Expand Disk Drives.
  4. Right-click the drive on which you want to turn disk write caching on or off, and then click Properties.
  5. Click the Policies tab.
  6. Click to select or clear the Enable write caching on the disk check box as appropriate.
  7. Click OK.

enter image description here

How can I Turn Disk Write Caching On or Off with a registry key (regedit) / command line? (to automate the process on several PCs)

PD: There is an option in C/C++, but it is outdated or not applicable. The same applies to the method used by dskcache.

8
  • Try Registry Key for Write Cache on Disk | PC Review
    – DavidPostill
    Commented Apr 9, 2019 at 20:50
  • not work (on 7/10 x64)
    – acgbox
    Commented Apr 9, 2019 at 21:05
  • 1
    This site -- gallery.technet.microsoft.com/scriptcenter/… -- has a Powershell script that will do it, but it needs dskcache.exe. The provided link is dead, and I haven't found a live one yet. But if you manage to find a copy of dskcache.exe, that might get you what you need.
    – Doug Deden
    Commented Apr 9, 2019 at 21:07
  • dskcache.exe is not compatible with w10
    – acgbox
    Commented Apr 9, 2019 at 21:14
  • Setting UserWriteCacheSetting should absolutely work on Windows 7+ when you tried that you did reboot and/or logout?
    – Ramhound
    Commented Apr 9, 2019 at 21:59

2 Answers 2

2

It seems that an old diskcache.exe, which had been distributed by Microsoft, has been lost. Try a compatible tool, made by me long ago.

https://www.vector.co.jp/soft/winnt/hardware/se487753.html

To enable write cache on disk 0,

.\diskcach 0 -w 1

To disable

.\diskcach 0 -w 0

It may require MSVC++ 2008 SP1 redistributable package.

3
  • It seems that it no longer works with w7 / 10 x64. Anyway, I appreciate the effort to design this tool
    – acgbox
    Commented May 10, 2019 at 23:03
  • 1
    I confirmed it worked on Windows 10 x64 (1809). However, some disk controllers may not accept change on cache settings. Also note that it requires to be run with admin privilege.
    – ynaka
    Commented May 11, 2019 at 6:36
  • ok. correct answer. it's as close as it can get. Fix answer and add more command options or help. Thanks
    – acgbox
    Commented May 11, 2019 at 15:41
2

I have created a function to enable/disable write disk caching for the system drive only. Restart needed.

Permanent link: https://github.com/farag2/Utilities/blob/master/Enable_disk_write_caching.ps1

<#
    .SYNOPSIS
    Configure the disk write caching

    .PARAMETER Disable
    Disable the disk write caching

    .PARAMETER Enable
    Enable the disk write caching

    .EXAMPLE
    DiskWriteCaching -Disable

    .EXAMPLE
    DiskWriteCaching -Enable

    .NOTES
    Current user
#>
function DiskWriteCaching
{
    param
    (
        [Parameter(
            Mandatory = $true,
            ParameterSetName = "Disable"
        )]
        [switch]
        $Disable,

        [Parameter(
            Mandatory = $true,
            ParameterSetName = "Enable"
        )]
        [switch]
        $Enable
    )

    # Get system drive ID regardless of the port number
    $Index = (Get-Partition | Where-Object -FilterScript {$_.DriveLetter -eq $env:SystemDrive[0]}).DiskNumber
    $SystemDriveID = (Get-CimInstance -ClassName CIM_DiskDrive | Where-Object -FilterScript {$_.Index -eq $Index}).PNPDeviceID
    # Get system drive instance
    $PSPath = (Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Enum\SCSI | Where-Object -FilterScript {$SystemDriveID -match $_.PSChildName}).PSPath
    # We need to go deeper... LeonardoDiCaprio.jpg
    $PSPath = (Get-ChildItem -Path $PSPath | Where-Object -FilterScript {$SystemDriveID -match $_.PSChildName}).PSPath

    # Check whether disk write caching is enabled
    $IsDeviceCacheEnabled = (Get-StorageAdvancedProperty -PhysicalDisk (Get-PhysicalDisk | Where-Object -FilterScript {$_.DeviceID -eq $Index})).IsDeviceCacheEnabled

    switch ($PSCmdlet.ParameterSetName)
    {
        "Disable"
        {
            if ($IsDeviceCacheEnabled)
            {
                if (-not (Test-Path -Path "$PSPath\Device Parameters\Disk"))
                {
                    # Create "Disk" folder
                    New-Item -Path "$PSPath\Device Parameters\Disk" -Force
                }

                # Disable disk write caching
                New-ItemProperty -Path "$PSPath\Device Parameters\Disk" -Name UserWriteCacheSetting -PropertyType DWord -Value 0 -Force
                New-ItemProperty -Path "$PSPath\Device Parameters\Disk" -Name CacheIsPowerProtected -PropertyType DWord -Value 0 -Force
            }
        }
        "Enable"
        {
            if (-not $IsDeviceCacheEnabled)
            {
                if (-not (Test-Path -Path "$PSPath\Device Parameters\Disk"))
                {
                    # Create "Disk" folder
                    New-Item -Path "$PSPath\Device Parameters\Disk" -Force
                }

                # Enable disk write caching
                New-ItemProperty -Path "$PSPath\Device Parameters\Disk" -Name UserWriteCacheSetting -PropertyType DWord -Value 1 -Force
                New-ItemProperty -Path "$PSPath\Device Parameters\Disk" -Name CacheIsPowerProtected -PropertyType DWord -Value 0 -Force
            }
        }
    }

    Write-Warning "Make sure to restart your PC!"
}

# DiskWriteCaching -Disable
# DiskWriteCaching -Enable
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .