Getting Device object of the CD ROM disk driver

Hi All,

What is the way to get the device object of the CD ROM disk driver, I need
to get that so that I can start filtering that.

Can I use ZwCreateFile(‘’\DosDevice\CDROM,…), to get the handle and from
the handle can I ge the device object of the CDROM driver.

Any information is helpful.

Thanks,
Kedar.

Actually you want to register as an upper filter driver for cdrom devices.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Kedar
Sent: Friday, April 09, 2004 11:55 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Getting Device object of the CD ROM disk driver

Hi All,

What is the way to get the device object of the CD ROM disk
driver, I need to get that so that I can start filtering that.

Can I use ZwCreateFile(‘’\DosDevice\CDROM,…), to get the
handle and from the handle can I ge the device object of the
CDROM driver.

Any information is helpful.

Thanks,
Kedar.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as:
xxxxx@hollistech.com To unsubscribe send a blank email to
xxxxx@lists.osr.com

No you cannot. Use PnP device interfaces instead.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Kedar”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Saturday, April 10, 2004 7:55 AM
Subject: [ntdev] Getting Device object of the CD ROM disk driver

> Hi All,
>
> What is the way to get the device object of the CD ROM disk driver, I need
> to get that so that I can start filtering that.
>
> Can I use ZwCreateFile(‘’\DosDevice\CDROM,…), to get the handle and from
> the handle can I ge the device object of the CDROM driver.
>
> Any information is helpful.
>
> Thanks,
> Kedar.
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

It’s been posted before, but here’s how you’d enumerate all the devices
using the SetupDi routines. I’ll use CDROM guids, which use identical
GUIDS for both the class and interface. The code below is pseudo-code,
and requires significant alteration for a shipping product, but should
be sufficient for you to find everything you need on MSDN.

========================================================================

// SetupDiGetClassDevs – gets the set of all devices of a specified
class,
// such as CdRomClassGuid (ntddstor.h).

GUID cdromGuid = CdRomClassGuid;
deviceInfoHandle =
SetupDiGetClassDevs(&cdromGuid, NULL, NULL,
(DIGCF_PRESENT | DIGCF_INTERFACEDEVICE));

for (int i = 0; i < 0x40000; i++)
{
SP_DEVICE_INTERFACE_DATA diData;
ULONG requiredSize = 0;
DWORD error;
RtlZeroMemory(&diData, sizeof(SP_DEVICE_INTERFACE_DATA));
diData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);

// SetupDiEnumDeviceInterfaces() – enumerates devices with a
specific
// interface GUID, such as CdRomClassGuid (ntddstor.h).
// request the Nth recorder – nonzero return on success
if (!SetupDiEnumDeviceInterfaces(deviceInfoHandle, 0,
&cdromGuid,
currentDeviceIndex, &diData))
{
DWORD error = GetLastError();
if (error == ERROR_NO_MORE_ITEMS)
{
break;
}
}
// SetupDiGetDeviceInterfaceDetail() – using the
DeviceInterfaceDetail
// returned above, call this twice (first to determine size
required,
// then to get info) to get the PNP path to the device.
// should never succeed with NULL buffer…
if (SetupDiGetDeviceInterfaceDetails(deviceInfoHandle, &diData,
NULL,
0, &requiredSize, NULL))
{
// throw Exception
}
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
// throw Exception – the error must always be
INSUFFICIENT_BUFFER
}
if (requiredSize == 0)
{
// throw Exception – size should never, ever be zero!
}
// allocate diDetails. Add sizeof(TCHAR) to ensure NULL
termination.
diDetails = Alloc(requiredSize+sizeof(WCHAR));
if (!SetupDiGetDeviceInterfaceDetails(deviceInfoHandle, &diData,
diDetails, requiredSize,
&updatedSize, NULL))
{
// thow Exception - should succeed this time around
}
// diDetails->DevicePath is a NULL-terminated unicode string
// save (or use) that string for opening the device directly

}

========

How to enumerate all devices of a class (such as CDROM) that have a
specific interface (such as IMAPI):

As above, but modify the interface GUID in SetupDiEnumDeviceInterfaces()
to use the IMAPI-specific GUID.

========================================================================

This posting is provided “AS IS” with no warranties, and confers no
rights. Use of included script samples are subject to the terms
specified at
http://www.microsoft.com/info/cpyright.htm

-----Original Message-----
From: Kedar [mailto:xxxxx@hotmail.com]
Sent: Friday, April 09, 2004 8:55 PM
Subject: Getting Device object of the CD ROM disk driver

Hi All,

What is the way to get the device object of the CD ROM disk driver, I
need
to get that so that I can start filtering that.

Can I use ZwCreateFile(‘’\DosDevice\CDROM,…), to get the handle and
from
the handle can I ge the device object of the CDROM driver.

Any information is helpful.

Thanks,
Kedar.