2

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.

acgbox
  • 741
  • 2
  • 13
  • 31
  • Try [Registry Key for Write Cache on Disk | PC Review](https://www.pcreview.co.uk/threads/registry-key-for-write-cache-on-disk.2550297/) – DavidPostill Apr 09 '19 at 20:50
  • not work (on 7/10 x64) – acgbox Apr 09 '19 at 21:05
  • 1
    This site -- https://gallery.technet.microsoft.com/scriptcenter/Change-write-caching-576747ad -- 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 09 '19 at 21:07
  • dskcache.exe is not compatible with w10 – acgbox Apr 09 '19 at 21:14
  • Setting **UserWriteCacheSetting** should absolutely work on Windows 7+ when you tried that you did reboot and/or logout? – Ramhound Apr 09 '19 at 21:59
  • @Ramhound I tried it on w7SP1x64 and nothing happens after restarting. But I'll try it on other computers and VMs and publish the result – acgbox Apr 09 '19 at 22:08
  • @Ramhound It is necessary to clarify that this method can not be automated because the IDs of the disks are different and can not be solved with a ".reg", therefore it does not apply in response to the question. (It is easier to do it in the graphic environment than with this method.) – acgbox Apr 09 '19 at 22:12
  • Your question makes no mention of automation only a registry file that sets the key. Likewise, with a little work this could be automated, might just require PowerShell or something similar in order to generate the .reg file. – Ramhound Apr 09 '19 at 22:50

2 Answers2

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.

ynaka
  • 36
  • 4
  • It seems that it no longer works with w7 / 10 x64. Anyway, I appreciate the effort to design this tool – acgbox May 10 '19 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 May 11 '19 at 06:36
  • ok. correct answer. it's as close as it can get. Fix answer and add more command options or help. Thanks – acgbox May 11 '19 at 15:41
1

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
farag
  • 149
  • 5