Applications that provide document scanning SHOULD provide a means of choosing the scanner. The mechanism is to send a command to the Data Source Manager “DSM” which then remembers the chosen default.
This provides an easy way of picking a default for any application. Just use an app that allows you to “Select Source …”, pick a source, and then use any application you like with that source.
TWAIN DSM Internals
If you want to choose a source yourself, under program control, here is how it all works …
The DSM was actually written by the TWAIN Working Group and is provided by Microsoft during a Windows install.
The TWAIN DSM source code is available on line.
As you can see, the hive used is HKEY_CURRENT_USER. The registry path used varies for 64 bit and 32 bit OSes. It is:
#define TWNDSM_DS_REG_LOC "Software\\Microsoft\\Windows NT\\CurrentVersion\\TWAIN64"
#define TWNDSM_DS_REG_LOC "Software\\Microsoft\\Windows NT\\CurrentVersion\\TWAIN"
The reason is also given in the source code:
#define kTWAIN_DS_DIR "twain_64"
#define kTWAIN_DS_DIR "twain_32"
// Work out the full path to our drivers (if needed)…
#if (TWNDSM_CMP == TWNDSM_CMP_VISUALCPP)
Setting the Registry
If you are writing a proper TWAIN application, you should choose the default source by calling functions within the DSM. However, given what the DSM currently does, an easy way to set the default document scanning device programatically is to add or update the registry setting directly. This is very straight forward in most languages (eg VB, VC++, VBA, .Net, VBScript).
A simple example is setting the default TWAIN Source using VBScript.
You could also supply or pick a registry settings file to “run”. That would cause RegEdit to load and do the update for you.
As always, exercise care when tinkering with the registry.