The Win32 subsystem seems to maintains some private data that keeps track of the assigned drive letters. I don’t know of any way to tell Win32 to update its available drive letter list (the one returned by GetLogicalDrives()) from kernel mode. However, you can broadcast a message from a Win32 app (hopefully you have a Win32 component in your product that can do this for you) that will cause Win32 to refresh the available drive letter list. The following content is a repeated response to an earlier/related question:
You need to broadcast a message (from a Win32 app) to all components letting them know that a new volume device has arrived (or been removed). You can this with the following code:
// Here’s how you call the function when you’ve removed a drive letter
// In this call, DriveLetter is the drive letter that you removed
BroadcastVolumeDeviceChange(DBT_DEVICEREMOVECOMPLETE, DriveLetter);
// Here’s how you call the function when you’ve added a drive letter
// In this call, DriveLetter is the drive letter that you added
BroadcastVolumeDeviceChange(DBT_DBT_DEVICEARRIVAL, DriveLetter);
// Call this function when you’ve added/removed a drive letter symbolic
// link in kernel mode. When using Win32 alone to create your symbolic
// link (using DefineDosDevice()), you’ll end up with symbolic links in
// the session namespace (which you probably don’t want) rather than
// the global namespace. The solution is to create the drive letter
// symbolic links in kernel mode, but then you’ll discover (as you did)
// that DefineDosDevice() does more than just create symbolic links… it
// also notifies everybody that a drive letter assignment was made. So
// if you create your symbolic links in kernel mode you’ll need to add this
// extra functionality, and as far as I can tell this function is sufficient.
HRESULT BroadcastVolumeDeviceChange(WPARAM notification, WCHAR DriveLetter)
{
static PDEV_BROADCAST_VOLUME pMyDevHdr = NULL;
DWORD dwFlag = BSM_ALLCOMPONENTS;
DWORD volumeMask = 1 << (DriveLetter - L’A’);
// Allocate our broadcast header and keep it around (static)
// We have to keep it around because if we post the broadcast the buffers that we
// pass into the broadcast have to stick around after this call returns.
if (NULL == pMyDevHdr)
{
pMyDevHdr = new DEV_BROADCAST_VOLUME;
}
// Initialize our broadcast header
pMyDevHdr->dbcv_devicetype = DBT_DEVTYP_VOLUME;
pMyDevHdr->dbcv_size = sizeof(DEV_BROADCAST_VOLUME);
pMyDevHdr->dbcv_flags = DBTF_NET;
pMyDevHdr->dbcv_unitmask = volumeMask;
// Broadcast the device change notification
BroadcastSystemMessage(BSF_IGNORECURRENTTASK,
&dwFlag,
WM_DEVICECHANGE,
notification,
(LPARAM)pMyDevHdr);
return S_OK;
}
BTW - This only works on W2K and above.
-----Original Message-----
From: Christiaan Ghijselinck [mailto:xxxxx@Compaqnet.be]
Sent: Thursday, September 26, 2002 1:04 PM
To: NT Developers Interest List
Subject: [ntdev] How can I remove Drive Letters from off-line devices
within XP ?
When one disables the Microsoft W2000 PnP RAMDisk sample ( Q257405 ) by
means of the device manager, the drive letters are updated within explorer
( the drive letter disappears ). If the RAMdisk is enabled again, the
drive letter reappears, even with a different value when the registry
setting “DriveLetter” of the RAMDisk has changed.
On XP however, the drive letter does not disappear, but get’s an
additional
“not available” question mark until reboot. What must be made to the
driver, to act in an identical way as on W2000 ? I assume that the Drive
Letter will appear spontaneously upon installation when I use
“IoRegisterDeviceInterface ( …MOUNTDEV_MOUNTED_DEVICE_GUID …)” within
the “AddDevice” function, but will this guarantee that the Drive Letter
will disappear when one disables the RAM disk ?
Note that the RAMDisk sample still uses “IoCreateSymbolicLink” which,
according the DDK documentation, should not be used within PnP Device
Drivers… nevertheless, it works on W2000 ! Changing the Q257405
suggested device type from FILE_DEVICE_VIRTUAL_DISK into FILE_DEVICE_DISK
for XP does not change this behaveour.
You are currently subscribed to ntdev as: xxxxx@powerquest.com
To unsubscribe send a blank email to %%email.unsub%%