|
-
January 13th, 2007, 12:32 PM
#1
How to monitor mount points via GUID_IO_VOLUME_MOUNT
Does anyone know how to get notification when a mount point is created?
I've tried the following code, but I get error 1066 from the RegisterDeviceNotification API.
BOOL RegisterDevBroadcastHandle(const std::string& VolumeName) //VolumeName in following format \\.\C:
{
SERVICE_STATUS_HANDLE &theServiceStatusHandle = serviceStatusHandle;
HANDLE dbch_handle = CreateFileA(VolumeName.c_str(),
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_NO_BUFFERING | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
NULL);
if (dbch_handle == INVALID_HANDLE_VALUE)
{
LogEvent("CreateFileA(%s) failed (hndl): %lu.", VolumeName.c_str(), GetLastError());
return FALSE;
}
DEV_BROADCAST_HANDLE NotificationFilter;
ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
NotificationFilter.dbch_size = sizeof(NotificationFilter);
NotificationFilter.dbch_devicetype = DBT_DEVTYP_HANDLE;
NotificationFilter.dbch_eventguid = GUID_IO_VOLUME_MOUNT;
NotificationFilter.dbch_handle = dbch_handle;
//The following line produces error 1066
HDEVNOTIFY hDevNotify = RegisterDeviceNotification( theServiceStatusHandle, &NotificationFilter, DEVICE_NOTIFY_SERVICE_HANDLE | DEVICE_NOTIFY_ALL_INTERFACE_CLASSES);
if(!hDevNotify)
{
CloseHandle(dbch_handle);
LogEvent("RegisterDeviceNotification failed (hndl): %lu; (%s), %i", GetLastError(), VolumeName.c_str(), (glbl_currentServiceRunningState == SERVICE_RUNNING));
return FALSE;
}
OpenVolumes[VolumeName] = dbch_handle;
ArrayOfHdevnotify.push_back(hDevNotify);
return TRUE;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|