I'm very prone to lose usb dongles, I want now to configure windows 'scheduled task' that each time it sees an event with 'insertion' of my drive it copys all the content in a specific folder (c>\usb_backups\<UUID>\<today's date>\)

Now I'm tracking event 2003 (usb drive mount) that contains the ID, but I'm not able to discover on wich drive letter the drive is mounted on.

The script invoked should be something like:

@xcopy /E /C /Q /H /Y %%sourcedrive%%\ %systemdrive%\usb_backups\%%UUID%%\%%date%%\

But, right now, I don't know how to set %%sourcedrive%% and %%UUID%% variables.

  • How does the loose usb dongle factor in? Does the drive get disconnected & subsequently corrupts it's filesystem? Maybe a more robust filesystem or settings would better help. And does xcopy only copy changed files, like rsync? Or changed parts of big files? Could be a lot of copying otherwise
    – Xen2050
    Feb 25, 2019 at 10:22
  • sorry for the typo: I just put a 'extra' o
    – DDS
    Feb 25, 2019 at 10:32
  • I just copy all the files each time... It's a personal pendrive I take with me with few important text files so copying all is feasable. Eventually I'll manually delete un-needed directories
    – DDS
    Feb 25, 2019 at 10:49
  • You could try USBDLM, it's a very handy utility and will exactly suit in your case
    – montonero
    Feb 25, 2019 at 11:41

1 Answer 1


It appears that USBDLM would work great, it describes itself as:

USBDLM is a Windows service that gives control over Windows' drive letter assignment for USB drives. Running as service makes it independent of the logged on user's privileges, so there is no need to give the users the privilege to change drive letters.

It automatically solves conflicts between USB drives and network or subst drives of the currently logged on user.

Furthermore you can define new default letters for USB drives and much more.

It works on Windows XP to Windows 10.

It's html help page [apparently translated from German?] says you can do things like one of these to copy files with a click, or automatically:

  • let show an balloontip on drive arrival which shows the assigned drive letter
  • run something on click on the balloontip
  • executing an autorun, also depending on the criterions mentioned above

It's settings are either in an .INI file, or the registry

The desired drive letters or mount points and other settings are defined in a text file called USBDLM.INI located in the same place as the USBDLM.EXE.

Modern applications often store their settings in the Windows registry but I don't like that. INI files are the 'classic' approach.


Settings in the Registry:

Since V3.3.1 USBDLM can read its settings from the registry too. It reads from
HKLM/Software/Uwe Sieber/USBDLM

If this registry key exists, then the USBDLM.INI is ignored! Only the log file settings are read from the INI then.

Actions on click on the Balloontip

Similar to autorun events you can define actions on left, right and middle click on the balloon.

;on left click, open a simple Explorer window with the drive
[OnBalloonClick] open="%windir%\explorer" %drive%

;on right click, open a foto software [OnBalloonRClick]
open="C:\Program Files\FotoSoft\fotosoft.exe" %drive%

You can define several events depending on criterions as shown for [AutoRun].

2. Global AutoRun settings in the USBDLM.INI

2.1 Triggered by volumes

Sample 2:

If the file DATA.TXT exist, copy it from the drive to C:\Data

open="%windir%\System32\cmd.exe" /c copy "%drive%\DATA.TXT" "C:\Data"

cmd is the Windows command processor, /c means "execute command and end then", copy is a command which the cmd knows and copies files.

Also useful might be to copy files on removal, BalloonTips have on removal settings, or an autorun (possibly time limited):

AutoRun on and after Removal

In analogy to the OnArrival function USBDLM can execute a command-line when a drive is "prepared for safe removal" and after a drive has been removed.

1. On preparation for safe removal

When a USB or Firewire drive becomes "prepared for safe removal" the USBDLM can react while the drive is still available.

This should not take too long, the maximum time is 30 Seconds under XP, and 15 Seconds since Vista/Win7. But while the notification is processed, no other events can be handled. Therefore USBDLM wait up to 10 Seconds only. If the started process is still running after this time, then USBDLM rejects the removal request. Windows then says "USBDLM prevents the removal...".

Sample to copy the file c:\test.txt to the folder \backup on the drive to remove:

open="%windir%\System32\cmd.exe" /c copy "C:\test.txt" %drive%\backup

As in the first sample but only if the file \backup\test.txt exists on the drive to remove:

open="%windir%\System32\cmd.exe" /c copy "C:\test.txt" %drive%\backup

There's several Variables available, like these useful looking ones

Variable             Description          Sample
--------             -----------          ------
%DriveLetter%        drive letter         X
%Drive%              drive                X:
%Root%               drive root           X:\
%DevName%            device name          Corsair Flash Voyager
%Label%              volume label         My flash drive
%Size%               volume size          16 GB
%KernelName%         kernel name          \Device\Harddisk3\DP(1)0-0+d
%PartitionName%      Partition name       \Device\Harddisk2\Partition1
%DiskSignature%      disk signature MBR   9810ABEF
%GptDiskIdGuid%      GPT disk ID GUID     {GUID}
%PureVolumeName%     pure volume name     Volume{GUID}
%DateISO%            Date (yyyy-mm-dd)    2016-10-31
%Time%               Time (hh:mm:ss)      12:00:00

[Thanks to montonero's comment for the idea]

  • Thankyou, next time I will, for now I'm using synctoy (found it online few days ago)
    – DDS
    Feb 28, 2019 at 7:55

You must log in to answer this question.

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