Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / August 2008



Tip: Looking for answers? Try searching our database.

Determine CD-ROM drive letter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve - 12 Aug 2008 11:35 GMT
Well I asked this question in another list and got no responses so I
am going to try here.  What I am trying to do is determine the CD-ROM
drive letter associated with a HostAdpater, DeviceID and LUN.

I am using wnaspi32.dll to get a list of CD drives on the system.
This provides me with:
1) Host Adapter
2) DeviceID
3) LUN
for each CD drive on the system.

What I need is a way to get the drive letter assigned to each of the
drives returned.  So IOW I need to find a way to lookup the drive
letter associated with the HostAdapter, DeviceID and LUN

Anybody got any advice?

Thanks,
Steve
Uwe Sieber - 12 Aug 2008 11:57 GMT
> Well I asked this question in another list and got no responses so I
> am going to try here.  What I am trying to do is determine the CD-ROM
[quoted text clipped - 12 lines]
>
> Anybody got any advice?

Please give us a sample of the availlable information.

Uwe
MikeD - 12 Aug 2008 13:12 GMT
> Well I asked this question in another list and got no responses so I
> am going to try here.  What I am trying to do is determine the CD-ROM
[quoted text clipped - 12 lines]
>
> Anybody got any advice?

Dunno about using the information you've mentioned, but if all you want is a
list of the CD/DVD drives installed, use the GetLogicalDriveStrings and
GetDriveType Win32 API functions.

-----BEGIN CODE
Option Explicit

Private Declare Function GetLogicalDriveStrings Lib "kernel32" _
Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long

Private Declare Function GetDriveType Lib "kernel32" Alias _
"GetDriveTypeA" (ByVal nDrive As String) As Long

Private Const DRIVE_CDROM = 5
Private Const DRIVE_FIXED = 3
Private Const DRIVE_RAMDISK = 6
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_REMOVABLE = 2

Private Sub Form_Load()

   Debug.Print GetCDDriveLetters

End Sub

Private Function GetCDDriveLetters() As String

   'Returns a semi-colon delimitted string of all CDROM
   'drives letters found on the system.

   Dim lRet            As Long
   Dim sBuffer         As String * 255
   Dim sDrives         As String
   Dim sDriveRoot      As String
   Dim iPos            As Integer
   Dim sTemp           As String

   lRet = GetLogicalDriveStrings(255, sBuffer)
   sDrives = UCase$(Left$(sBuffer, lRet))
   iPos = InStr(1, sDrives, vbNullChar)

   Do Until iPos = 0
       sDriveRoot = Left$(sDrives, iPos - 1)

       'Get rid of the backslash
       If Right$(sDriveRoot, 1) = "\" Then
           sDriveRoot = Left$(sDriveRoot, Len(sDriveRoot) - 1)
       End If

       If GetDriveType(sDriveRoot) = DRIVE_CDROM Then
           sTemp = sTemp & sDriveRoot & ";"
       End If

       sDrives = Mid$(sDrives, iPos + 1)
       iPos = InStr(1, sDrives, vbNullChar)
   Loop

   'Remove the last semi-colon
   sTemp = Left$(sTemp, Len(sTemp) - 1)

   GetCDDriveLetters = sTemp

End Function
-----END CODE

Signature

Mike
Microsoft MVP Visual Basic

Steve - 12 Aug 2008 13:28 GMT
> > Well I asked this question in another list and got no responses so I
> > am going to try here.  What I am trying to do is determine the CD-ROM
[quoted text clipped - 84 lines]
>
> - Show quoted text -

Mike,

Thanks but I need to be able to find the drive associated with the
information I have.  If it is of any value, getting that information I
am using is demonstrated by Steve McMahon at his vbAccelerator site.
He has a demo app where he is finding the TOC and CDDB ID of the CD
currently in the drive.  To get a list of drives he uses the wnaspi32
dll.  He mentions in the article and in his code that he plans to show
how to resolve the drive letter from the information presented but I
have not yet found where he actually did it.

Here is a link to the sample on his site
http://www.vbaccelerator.com/home/VB/code/vbMedia/Audio/CD_Tracklistings/article.asp

Steve
mayayana - 12 Aug 2008 16:47 GMT
You can use WMI. It's a bit hokey, but it
does provide a great deal of system info.
and may be more widely available than
wnaspi.dll. (I looked up that file and found lots
of links to problems due to the file not being
present.)

  The following is a sample VBScript that returns
drive letter and deviceID. There are lots of other
CD properties available, but I don't know whether
you can get everything you need with just WMI.

--------------------------

DIM WMI, Col, Ob, s2

Set WMI = GetObject("WinMgmts:")
Set Col = WMI.ExecQuery("Select * from Win32_CDROMDrive")
 For Each Ob in Col
    S2 = S2 & "Device ID: " & Ob.DeviceID & vbCrLf
    S2 = S2 & "Drive Letter: " & Ob.Drive & vbCrLf
    S2 = S2 & "Manufacturer: " & Ob.Manufacturer & vbCrLf & vbCrLf
 Next

MsgBox s2
Set Col = Nothing
Set WMI = Nothing

> Well I asked this question in another list and got no responses so I
> am going to try here.  What I am trying to do is determine the CD-ROM
[quoted text clipped - 15 lines]
> Thanks,
> Steve
Steve - 12 Aug 2008 17:07 GMT
>   You can use WMI. It's a bit hokey, but it
> does provide a great deal of system info.
[quoted text clipped - 45 lines]
>
> - Show quoted text -

That looks very promising.  Can you tell me where I might find some
documentation on what values are avialable.

Thanks,
Steve
mayayana - 12 Aug 2008 21:13 GMT
That looks very promising.  Can you tell me where I might find some
documentation on what values are avialable.
-------

 Below is the list of CDROMDrive properties. My apologies
that it's a bit big for a post. There's a WMI SDK somewhere,
but I don't have a link offhand. WMI offers a lot of system
info. but it requires that WMI be installed and running.
(Usually not a problem post-Win98.) It's also rather confusing,
with a very clunky syntax that inexplicably emulates SQL.

 Most of the WMI stuff is just wrappers around other tools
that are easier than WMI to use, but I don't know of any
other way to get such extensive system info. (Much of it
is in the Registry but WMI also seems to have new low-level
functions. For instance, I can return CPU speed on Win9x,
which is not normally possible.)

  There was an article about using WMI i VB in the Sept.
2000 VBPJ. That might be helpful if you can find it. My
own experience has only been with using it in script.

------------------------
 CDROMDrive Properties:
------------------------

Property Description
Availability uint16
Read-only
Availability and status of the device. Power Save - Unknown indicates that
the device is known to be in a power save mode, but its exact status is
unknown; Power Save - Low Power Mode indicates that the device is in a power
save state but still functioning, and may exhibit degraded performance;
Power Save - Standby indicates that the device is not functioning but could
be brought to full power quickly; and Power Save - Warning indicates that
the device is in a warning state, though also in a power save mode.

Values are:
1 = Other
2 = Unknown
3 = Running/Full Power
4 = Warning
5 = In Test
6 = Not Applicable
7 = Power Off
8 = Off Line
9 = Off Duty
10 = Degraded
11 = Not Installed
12 = Install Error
13 = Power Save - Unknown
14 = Power Save - Low Power Mode
15 = Power Save - Standby
16 = Power Cycle
17 = Power Save - Warning

Capabilities array (uint16)
Read-only
Capabilities of the media access device. For example, the device may support
random access (3), removable media (7), and automatic cleaning (9).

Values are:
0 = Unknown
1 = Other
2 = Sequential Access
3 = Random Access
4 = Supports Writing
5 = Encryption
6 = Compression
7 = Supports Removable Media
8 = Manual Cleaning
9 = Automatic Cleaning

CapabilityDescriptions array (string)
Read-only
List of more detailed explanations for any of the access device features
indicated in the Capabilities array. Note, each entry of this array is
related to the entry in the Capabilities array that is located at the same
index.

Caption string
Read-only
Short description (one-line string) of the object.

CompressionMethod string
Read-only
Algorithm or tool used by the device to support compression. If it is not
possible or not desired to describe the compression scheme (perhaps because
it is not known), use the following words: "Unknown" to represent that it is
not known whether the device supports compression capabilities or not;
"Compressed" to represent that the device supports compression capabilities
but either its compression scheme is not known or not disclosed; and "Not
Compressed" to represent that the devices does not support compression
capabilities.

ConfigManagerErrorCode uint32
Read-only
Win32 Configuration Manager error code. For values, see
ConfigManagerErrorCode.

ConfigManagerUserConfig Boolean
Read-only
Indicates whether the device is using a user-defined configuration.

CreationClassName string
Read-only
Qualifiers: Key, MaxLen(256)
Name of the first concrete class to appear in the inheritance chain used in
the creation of an instance. When used with the other key properties of the
class, the property allows all instances of this class and its subclasses to
be uniquely identified.

DefaultBlockSize uint64
Read-only
Default block size, in bytes, for this device.

Description string
Read-only
Description of the object.

DeviceID string
Read-only
Qualifiers: Key
Uniquely identifies this CD-ROM drive.

Drive string
Read-only
Drive letter of the CD ROM drive.

Example: "d:\"

DriveIntegrity Boolean
Read-only
Indicates whether files can be accurately read from the CD device. This is
achieved by reading a block of data twice and comparing the data against
itself.

ErrorCleared Boolean
Read-only
Indicates whether the error reported in LastErrorCode is now cleared.

ErrorDescription string
Read-only
More information about the error recorded in LastErrorCode, and information
on any corrective actions that may be taken.

ErrorMethodology string
Read-only
Type of error detection and correction supported by this device.

FileSystemFlags uint16
Read-only
Qualifiers: Deprecated

The FileSystemFlags property is deprecated in favor of FileSystemFlagsEx

FileSystemFlagsEx uint32
Read-only
File system flags associated with the Win32 CD-ROM drive. This parameter can
be any combination of flags, but FS_FILE_COMPRESSION and
FS_VOL_IS_COMPRESSED are mutually exclusive.

Values are:
0x00000001 = CASE_SENSITIVE_SEARCH
0x00000002 = CASE_PRESERVED_NAMES
0x00000004 = UNICODE_ON_DISK
0x00000008 = PERSISTENT_ACLS
0x00000010 = FILE_COMPRESSION
0x00000020 = VOLUME_QUOTAS
0x00000040 = SUPPORTS_SPARSE_FILES
0x00000080 = SUPPORTS_REPARSE_POINTS
0x00000100 = SUPPORTS_REMOTE_STORAGE
0x00004000 = SUPPORTS_LONG_NAMES
0x00008000 = VOLUME_IS_COMPRESSED
0x00010000 = SUPPORTS_OBJECT_IDS
0x00020000 = SUPPORTS_ENCRYPTION
0x00040000 = SUPPORTS_NAMED_STREAMS

Example: 0

Id string
Read-only
Drive letter uniquely identifying this CD-ROM drive.

Example: "d:\"

InstallDate datetime
Read-only
When the object was installed. A lack of a value does not indicate that the
object is not installed.

LastErrorCode uint32
Read-only
Last error code reported by the logical device.

Manufacturer string
Read-only
Manufacturer of the Win32 CD-ROM drive.

Example: "PLEXTOR"

MaxBlockSize uint64
Read-only
Maximum block size, in bytes, for media accessed by this device.

MaximumComponentLength uint32
Read-only
Maximum length of a filename component supported by the Win32 CD-ROM drive.
A filename component the portion of a filename between backslashes. The
value can be used to indicate that long names are supported by the specified
file system. For example, for a FAT file system supporting long names, the
function stores the value 255, rather than the previous 8.3 indicator. Long
names can also be supported on systems that use the NTFS file system.

Example: 255.

MaxMediaSize uint64
Read-only
Maximum size, in kilobytes, of media supported by this device.

MediaLoaded Boolean
Read-only
Indicates whether a CD-ROM is in the drive.

MediaType string
RRead-only
Type of media used or accessed by this device. In this class, the value will
always be "CD-ROM".

Values are:
"Random Access"
"Supports Writing"
"Removable Media"
"CD-ROM"

MinBlockSize uint64
Read-only
Minimum block size, in bytes, for media accessed by this device.

Name string
Read-only
Label by which the object is known. When subclassed, the property can be
overridden to be a key property.

NeedsCleaning Boolean
Read-only
Indicates whether the media access device needs cleaning. Whether manual or
automatic cleaning is possible is indicated in the Capabilities property.

NumberOfMediaSupported uint32
Read-only
When the media access device supports multiple individual media, this
property defines the maximum number which can be supported or inserted.

PNPDeviceID string
Read-only
Win32 Plug and Play device identifier of the logical device.

Example: "*PNP030b"

PowerManagementCapabilities array (uint16)
Read-only
Indicates the specific power-related capabilities of a logical device. The
Enabled value indicates that the power management features are currently
enabled but the exact feature set is unknown or the information is
unavailable. Power Saving Modes Entered Automatically indicates that a devic
e can change its power state based on usage or other criteria. Power State
Settable indicates that the SetPowerState method is supported. Power Cycling
Supported indicates that the SetPowerState method can be invoked with the
PowerState parameter set to 5 (Power Cycle). Timed Power On Supported
indicates that the SetPowerState method can be invoked with the PowerState
parameter set to 5 (Power Cycle) and Time set to a specific date and time,
or interval, for power-on.

Values are
0 = Unknown
1 = Not Supported
2 = Disabled
3 = Enabled
4 = Power Saving Modes Entered Automatically
5 = Power State Settable
6 = Power Cycling Supported
7 = Timed Power On Supported

PowerManagementSupported Boolean
Read-only
Indicates whether the device can be power-managed (can be put into suspend
mode, and so on). The property does not indicate that power management
features are currently enabled, only that the logical device is capable of
power management.

RevisionLevel string
Read-only
Firmware revision level of the Win32 CD-ROM drive.

SCSIBus uint32
Read-only
SCSI bus number for the disk drive.

Example: 0

SCSILogicalUnit uint16
Read-only
SCSI logical unit number (LUN) of the disk drive. The LUN is used to
designate which SCSI controller is being accessed in a system with more than
one controller being used. The SCSI device identifier is similar, but is the
designation for multiple devices on one controller.

Example: 0

SCSIPort uint16
Read-only
SCSI port number of the disk drive.

Example: 1

SCSITargetId uint16
Read-only
SCSI identifier number of the Win32 CD-ROM drive.

Example: 0

Size uint64
Read-only
Qualifiers: Units(Bytes)
Size of the disk drive.

Status string
Read-only
Current status of the object. Various operational and non-operational
statuses can be defined. Operational statuses include: "OK", "Degraded", and
"Pred Fail" (an element, such as a SMART-enabled hard drive, may be
functioning properly but predicting a failure in the near future).
Non-operational statuses include: "Error", "Starting", "Stopping", and
"Service". The latter, "Service", could apply during mirror-resilvering of a
disk, reload of a user permissions list, or other administrative work. Not
all such work is on-line, yet the managed element is neither "OK" nor in one
of the other states.

Values are:
"OK"
"Error"
"Degraded"
"Unknown"
"Pred Fail"
"Starting"
"Stopping"
"Service"

StatusInfo uint16
Read-only
State of the logical device. If this property does not apply to the logical
device, the value 5 (Not Applicable) should be used.

Values are:
1 = Other
2 = Unknown
3 = Enabled
4 = Disabled
5 = Not Applicable

SystemCreationClassName string
Read-only
Value of the scoping computer's CreationClassName property.

SystemName string
Read-only
Name of the scoping system.

TransferRate real64
Read-only
Qualifiers: Units(KiloBytes per Second)
Transfer rate of the CD-ROM drive. A value of -1 indicates that the rate
could not be determined. This could happen, for example, if the CD is not in
the drive.

VolumeName string
Read-only
Volume name of the Win32 CD-ROM drive.

VolumeSerialNumber string
Read-only
Volume serial number of the media in the CD-ROM drive.

Example: A8C3-D032
Steve - 13 Aug 2008 20:04 GMT
> That looks very promising.  Can you tell me where I might find some
> documentation on what values are avialable.
[quoted text clipped - 381 lines]
>
> Example: A8C3-D032

Thanks
MikeD - 13 Aug 2008 20:42 GMT
>> Thanks

Don't quote the whole damn message just to say thanks at the VERY end! Any idea how annoying it is to scrolll through everything you
quoted just to see your reply was nothing but "Thanks"?

You need to learn to trim what you're quoting when you reply. <g> Only quote what is necessary for your reply to make sense.

Signature

Mike
Microsoft Visual Basic MVP

Steve Easton - 14 Aug 2008 23:59 GMT
>>> Thanks
>
[quoted text clipped - 3 lines]
> You need to learn to trim what you're quoting when you reply. <g> Only quote what is necessary for your
> reply to make sense.

But, but but but ...it was bottom posted.!!!
<gd&r>

Signature

Steve Easton

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.