1

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
  • not work (on 7/10 x64)
    – ajcg
    Apr 9 '19 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
    Apr 9 '19 at 21:07
  • dskcache.exe is not compatible with w10
    – ajcg
    Apr 9 '19 at 21:14
  • Setting UserWriteCacheSetting should absolutely work on Windows 7+ when you tried that you did reboot and/or logout?
    – Ramhound
    Apr 9 '19 at 21:59
1

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
    – ajcg
    May 10 '19 at 23:03
  • 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
    May 11 '19 at 6:36
  • ok. correct answer. it's as close as it can get. Fix answer and add more command options or help. Thanks
    – ajcg
    May 11 '19 at 15:41
0

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/Disk%20write%20caching.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 it's pluggled in
    $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 CacheIsPowerProtected -PropertyType DWord -Value 0 -Force
                New-ItemProperty -Path "$PSPath\Device Parameters\Disk" -Name UserWriteCacheSetting -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 CacheIsPowerProtected -PropertyType DWord -Value 0 -Force
                New-ItemProperty -Path "$PSPath\Device Parameters\Disk" -Name UserWriteCacheSetting -PropertyType DWord -Value 1 -Force
            }
        }
    }

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

# DiskWriteCaching -Disable
# DiskWriteCaching -Enable
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.