3

I'm working on an embedded computer in kiosk mode, where the users can insert an USB flash drive.

Even if I add a "Eject USB storage device" button in my app's GUI, often, some users won't use it and unplug their device directly.

How can I configure Windows such that all USB flash drives inserted in the future won't require "Eject"?

(Even if the transfers are slower, it's fine).

I know that once a USB flash drive is inserted, we can set this setting for this particular device, and uncheck these 2 checkboxes:

enter image description here

but how to make this setting for all devices that will be plugged in the future?

Link on the Microsoft website.

Basj
  • 1,489
  • 7
  • 47
  • 90
  • Are you actually running Windows 7? I seem to recall those options existing only on newer versions of Windows. – Ramhound Oct 04 '22 at 14:19
  • Update to Windows 10 and it will be disabled by default. – harrymc Oct 04 '22 at 14:22
  • Yes, as @harrymc points out, as of Windows 10, version 1809.. it is disabled by default. In your KIOSK.. are the drives meant to be WRITTEN TO or only READ FROM? – Señor CMasMas Oct 04 '22 at 14:34
  • @SeñorCMasMas Both read and write. – Basj Oct 17 '22 at 15:31
  • You have put up a bounty, but have not answered about the possibility of upgrading to Windows 10. So what kind of a "canonical answer" are you looking for? – harrymc Oct 17 '22 at 19:00
  • @harrymc Even though we mainly use Win10, we would like to keep Win7 support for this feature. – Basj Oct 17 '22 at 19:09
  • You still have to use Safe Remove anyway to guarantee the filesystem won't be corrupted. Disabling write caching just makes it less likely. You wouldn't know when a change is truly fully written to the drive. – Daniel B Oct 18 '22 at 22:05
  • @DanielB It seems that no, it's not needed. See https://i.stack.imgur.com/wLd47.png dialog box: "Quick removal (default) [...] you can disconnect the device safely *without using the Safely Remove Hardware notification icon*". – Basj Oct 19 '22 at 06:47

2 Answers2

1

As said in the comments, in Windows 10 version 1809 and later, the write cache is disabled by default for removable devices: official source.

For Windows 7, I might have the building blocks you need to create the solution, but I can't test a complete solution because I don't have the right environment. My apologies if it doesn't work.

The building blocks are as follows :

  • Find out the physical address of the USB drive, such as PHYSICALDRIVE3, by connecting a USB and using the following command in CMD:

    wmic diskdrive list brief
    
  • For disabling the write cache for the device, you will need the old and disappeared utility described in Microsoft Knowledge Base Article - 811392 (Internet Archive link)

  • I have found a download link for the utility in dskcache.exe File Download

  • The command for disabling the write cache requires Administrator permission and looks like this in CMD:

    dskcache.exe -w PHYSICALDRIVE3
    
  • If this old program works on Windows 7, you could set the Task Scheduler to run it automatically when a USB is introduced. See this answer.

An alternative to dskcache is described in this answer and can be downloaded from here (the text is in Chinese but the big green button is unmistakable).

Basj
  • 1,489
  • 7
  • 47
  • 90
harrymc
  • 455,459
  • 31
  • 526
  • 924
  • Thanks a lot for your answer @harrymc. Do you think a Task scheduler task is mandatory, or `dskcache.exe` could have the effect to set this parameter once for all for all future flash drives that will be inserted? Maybe changing a setting on `PHYSICALDRIVE3` will do it for all future flash drives connected on this same USB socket? – Basj Oct 18 '22 at 10:41
  • Something else: do you think there is a registry key that decides if write cache is enabled/disabled by default for all removable USB storage devices? – Basj Oct 18 '22 at 10:42
  • 1
    As `dskcache` accepts a physical drive designation, it might work for all USBs. I tend to think that it won't work, but only testing will tell. – harrymc Oct 18 '22 at 10:51
  • 1
    There is a `UserWriteCacheSetting` registry key under `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\IDE\ ...`, but it has two problems: (1) You need the device ID to find the right registry sub-key, so it works for one particular device only which will then be remembered, (2) A reboot might be required. If you're interested, see for example this [PowerShell script](https://github.com/farag2/Utilities/blob/master/Enable_disk_write_caching.ps1) that you can adapt for disabling. – harrymc Oct 18 '22 at 10:52
1

I may have overthought this question.

Quick removal seems to be the default on both Windows 7 and Windows 10. I just tried by inserting a flash drive:

enter image description here

I wonder if it's the default for all USB flash drives? Or if USB2 / USB3 will change anything?

(Remark: Then why did we all take the habit to click "Safely remove..." in the tray notification icon if quick removal is the default?)

Basj
  • 1,489
  • 7
  • 47
  • 90
  • Microsoft has announced this change for Windows 10, but it's possible that it was quietly back-ported to Windows 7. Better test with several USB devices of various type (sticks, disks) that you never used on this computer. – harrymc Oct 18 '22 at 12:57
  • Thanks @harrymc. Would you have a link about this change for Win10 (out of curiosity)? I never know where to search such things on the official Microsoft website. – Basj Oct 18 '22 at 15:27
  • https://learn.microsoft.com/en-us/windows/client-management/change-default-removal-policy-external-storage-media – harrymc Oct 18 '22 at 15:33
  • 1
    From memory only, so I may be wrong or there may be other nuance, but for a very long time my understanding has been that USB flash drives have defaulted to quick removal, while USB hard drives default to write caching. I want to say this is related to FAT on flash and NTFS on HDD, but it's my anecdotal memory and I'm not going to take time to research and write it up formally as an answer. – Doug Oct 21 '22 at 16:43
  • That's probably right @Doug! If someone has precision about this, feel free to post an answer. – Basj Oct 21 '22 at 18:50