Settings
Even the section [Settings] is mentioned here again and again, all settings have to be together within the one and only section [Settings]! There can be only one...
Most settings take effect immediately.
Check drive letters on startup
All settings are applied on startup too to catch internal card readers and drives that are attached while booting.
If USBDLM shall not do so:
[Settings]
CheckLettersOnStartup=0
Upcoming network drives cannot be considered here because they do not exist at this time and USBDLM cannot look into the future. Therefore network drives that shall be considered must be configured in section [NetworkLetters].
Check drive letters on user logon / user switch
Under XP and higher all settings are applied on user logon to take user depending settings effect when a different user logs on.
If USBDLM shall not do so:
[Settings]
CheckLettersOnLogon=0
Windows 2000 does not support the required notification messages, so USBDLM cannot check drive letters on user switches.
Check drive letters on resume from standby or hibernation
Some Windows installations wake up with screwed up drive letters after resume. If required, USBDLM can check the letters on resume. This is deactivated by default because it's usually not required.
[Settings]
CheckLettersOnResume=1
AutoRuns on user logon / user switch
Configured AutoRun events are executed by default on arrival of a drive or on insertion of a media only.
If USBDLM shall do this on user logon or user switch for drives which are already present:
[Settings]
AutoRunOnLogon=1
With an auto logon the USBDLM service may not be started yet on logon, so it misses the logon event. Workaround: When there are fewer than two minutes since the system is started and the a user is already logged on when the USBDLM services starts, then the AutoRuns are executed too.
Windows 2000 does not support the required notification messages, so USBDLM cannot execute AutoRun on logon.
Safe command lines
On command lines which contain spaces USBDLM tries to guess where the executable ends and the params begin, e.g.
open="C:\Program Files\tool.exe"
could be either C:\Program Files\tool.exe as executable without params or it could be C:\Program.exe with Files\tool.exe as param.
USBDLM would execute C:\Program Files\tool.exe but there are more difficult cases where it might execute the wrong one.
With SafeCommandLines=1 USBDLM does not accept command-lines which contain spaces but the executable file not quoted.
Samples of invalid command lines:
open=C:\Program Files\tool.exe
open=C:\Tools\tool.exe /x
Samples of valid command lines:
open="C:\Program Files\tool.exe"
open="C:\Tools\tool.exe" /x
Default is 0 to prevent existing configurations failing but the USBDLM_sample.ini has it set 1:
[Settings]
SafeCommandLines=1
UsbDriveInfo scans the settings for ambiguous / invalid command-lines and shows are warning or error depending on the SafeCommandLines setting.
Delete NTFS folders on drive removal
In contrast to drive letters, folders used as mount points are not removed when the mounted drive is removed by Windows. USBDLM removes the folder by default.
If it no shall do so:
[Settings]
DeleteMountPointsOnRemoval=0
Policy "Optimize for performance" for USB drives
Under XP and higher for USB drives there are the policies "Optimize for quick removal" (default) and "Optimize for performance". For the latter Windows pretends to activate a write cache. But it does not when the drive is a "Removable drive" as most of the USB flash drives are.
The only effect is that it's allowed then to format them with the NTFS file system. And with NTFS, XP and higher indeed activate a write cache, also on other computers because the write cache on NTFS drives is independent of the policy. It's all about the permission to format a "Removable drive" with NTFS.
For FAT formatted USB harddrives "Optimize for performance" indeed activates a write cache. With NTFS there is always a write cache.
USBDLM can set the policy "Optimize for performance" for all USB drives:
[Settings]
OptimizeUsbDrivesForSpeed=1
For drives attached for the first time it works immediately. Existing drives must be reattached two times (on first reattach the entry is made, on second reattach it takes effect).
The Windows 10 Task Manager shows USB removable drives on its Performance tab when they are "optimized for performance".
Force the activation of a write cache USB drives
Under XP and higher FAT formatted USB drives have no write cache by default. For USB harddrives (DriveType FIXED) a write cache can be activated by setting the policy "Optimize for performance" while this has no effect for removable USB drives (DriveType REMOVABLE).
By a registry value the activation can be forced, its name is WriteCacheEnableOverride, setting it to 1 activates a write cache even on FAT formatted USB removable drives.
Of course it is required then to use the "Safely remove hardware" facility or another tool as my RemoveDrive or EjectMedia to prevent data losses.
USBDLM can set the value to 1 for all USB drives:
[Settings]
UsbWriteCacheEnable=1
For drives attached for the first time it works immediately. Existing drives must be reattached two times (on first reattach the entry is made, on second reattach it takes effect).
- UsbWriteCacheEnable=0 -> set WriteCacheEnableOverride to 0
- UsbWriteCacheEnable=1 -> set WriteCacheEnableOverride to 1
- UsbWriteCacheEnable=-1 -> do not change WriteCacheEnableOverride (default)
External mount events
When drive letters are changed by another software then a service as USBDLM isn't notified off hand. To get notified a simple solution is an invisible Window. Since Vista and under XP when more than one user is logged on a window is not good enough, a window in the context of the interactive user is required. That's what the USBDLM_usr.exe is for. It receives the notifications and sends them down to the USBDLM service.
If this is all not required:
[Settings]
ExternalMountEvents=0
The OnArrival events and the balloon tips for mounted TrueCrypt, Network and Subst drives depend on this too.
By default USBDLM determines if the USBDLM_usr.exe is required by looking at [Settings] ExternalMountEvents, [Balloons] ShowVirtual and the used OnArrival/OnRemoval sections.
Loading the USBDLM_usr.exe can be controlled manually, see Technical Information too:
[Settings]
LoadUsbdlm_Usr=0
- 0: never load
- 1: load as required (default)
- 2: always load (with UAC for the restricted user)
- 3: always load (with UAC for the restricted and for the elevated user)
Volume Information Timeout
When looking for a file and when determining the volume label, volume serial and file system name USBDLM waits up to this time in Milliseconds before it gives up. Default is 10 Seconds:
[Settings]
VolumeInformationMaxWait=10000
Start the Windows Disk Management for uninitialized disks
When a drive arrives which has only zeros in the first sector then USBDLM can open the Windows Disk Management which then asks to initialize it.
[Settings]
StartDiskMgmtForUninitializedDrives=1
- 0: never
- 1: for USB harddrives (default)
- 2: for all harddrives
Debug Information
If there are problems I may figure out what is wrong by reading the debug logs which USBDLM writes.
It can write a log file or live output that can be grabbed by tools as SysInternals DebugView or TraceSpy.
To activate the log file set WriteLogFile=1, for the live output WriteDebugOutput=1.
To control how detailed the output is, set the LogLevel=1 to 5, 3 is usually good enough.
The file is _USBDLM.LOG in the root folder of the Windows drive by default but can be changed:
[Settings]
WriteDebugOutput=1
LogLevel=3
WriteLogFile=1
LogFile=C:\USBDLM.LOG
Since V4.2 no restart is required to take effect. The log file settings are read from the INI only, even when the Registry is used for other settings.
On startup of the USBDLM service the USBDLM.LOG is deleted. To avoid loosing interesting logs USBDLM creates two backups by default, so USBDLM_BAK2.LOG is deleted, USBDLM_BAK1.LOG renamed to USBDLM_BAK2.LOG and USBDLM.LOG is renamed to USBDLM_BAK1.LOG.
The number of backup files can be set:
LogFileBakCount=2
If you need the date in front of each log line:
LogShowDate=1
If you don't need Timing, Loglevel and Thread-ID:
LogShowTech=0
Flush and Dismount on Standby and Hibernation
When Windows enters Standby or Hibernation mode USBDLM flushes the file cache of all volumes. But the file systems stay mounted, therefore it is not a good idea to boot another operating system and mount the file system here too. This will lead to inconsistencies.
USBDLM can try to dismount all volumes on standby or hibernation:
[Settings]
DismountOnSleep=1
Dismounting succeeds only if there are no open files on a volume. The dismounting can be forced for USB and other hotplug drives by setting DismountOnSleep=2 but this makes all open file handles invalid, so on resume applications might complain or fail.
DismountOnSleep=3 forces it for all types of volumes.
Since V5.1 sleeping drive are not woken up for this unless DismountOnSleep=4..
Of course the system volume is not dismounted.
Removed write access on USBDLM.EXE and USBDLM.INI
By default USBDLM checks on startup if USBDLM.EXE and USBDLM.INI can be written by non-admins. If so, then it changes the file privileges. If you don't want this:
[Settings]
FixUsbdlmFilePrivileges=0
Command interface for programs with limited privileges
Some useful Windows function require admin privileges even they are harmless, e.g. flushing a drive's write cache.
Since V4.8 USBDLM has a command interface for some functions. Which functions are available can be configured:
Values of the function, add them if more than one is desired:
no function 0 (default)
flush the write cache 1
dismount a volume 2
eject a media 4
force dismount/eject 8
safely remove hardware 16
take volume on/offline 32
reactivate code 21/47 dev 64
Sample for all but the "force" one: (1+2+4+16+32+64):
[Settings]
CommandInterface=119
Sample for all: (1+2+4+8+16+32+64):
[Settings]
CommandInterface=127
Of course you can just set all bits by means of 255, 65535, 0xFF etc.
A USBDLM restart required to take effect.
Locking a volume is the prerequisite for dismounting correctly because it ensures that no one else is accessing the volume. Dismounting without a lock means dismounting by force. Open files stay open but accessing them leads to an error. The affected software will not like this. But if the open files are no more accessed anyway then there is no problem.
Tools which use the functions:
- FFB: Flushing the write cache and dismount
- EjectMedia: Flushing the write cache, dismount, eject, take volume offline
- LoadMedia: Loading a media, take a volume online
- RemoveDrive: Flushing the write cache, dismount, eject, reactivatable safely remove hardware
- RestartSrDev: Reactivating "Code 21/47" devices