Skip to main content
variables
Source Link
Xen2050
  • 14.1k
  • 4
  • 25
  • 42
[OnRemovalRequest]  
FileExists=%drive%\backup\test.txt
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
[OnRemovalRequest] FileExists=%drive%\backup\test.txt
open="%windir%\System32\cmd.exe" /c copy "C:\test.txt" %drive%\backup
[OnRemovalRequest] 
FileExists=%drive%\backup\test.txt
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
Missed 4 spaces in quoted code formatting
Source Link
Xen2050
  • 14.1k
  • 4
  • 25
  • 42

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

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

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

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

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

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

[OnRemovalRequest]
open="%windir%\System32\cmd.exe" /c copy "C:\test.txt" %drive%\backup
[OnRemovalRequest] FileExists=%drive%\backup\test.txt
open="%windir%\System32\cmd.exe" /c copy "C:\test.txt" %drive%\backup
Source Link
Xen2050
  • 14.1k
  • 4
  • 25
  • 42

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].


  1. 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

[OnArrival1]
FileExists=%drive%\DATA.TXT
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:

[OnRemovalRequest] 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:

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

[Thanks to montonero's comment for the idea]