|
|
|
Click here to copy the following block | Private Type DEVICE_MEDIA_INFO Cylinders As Double MediaType As STORAGE_MEDIA_TYPE TracksPerCylinder As Long SectorsPerTrack As Long BytesPerSector As Long NumberMediaSides As Long MediaCharacteristics As Long End Type Private Type GET_MEDIA_TYPES DeviceType As Long MediaInfoCount As Long MediaInfo(0) As DEVICE_MEDIA_INFO End Type
Const IOCTL_STORAGE_GET_MEDIA_TYPES_EX As Long = &H2D0C04 Const GENERIC_READ As Long = &H80000000 Const GENERIC_WRITE As Long = &H40000000 Const FILE_SHARE_READ As Long = &H1 Const FILE_SHARE_WRITE As Long = &H2 Const OPEN_EXISTING As Long = 3 Const INVALID_HANDLE_VALUE As Long = -1 Const ERROR_ACCESS_DENIED As Long = 5& Const ERROR_NOT_READY As Long = 21& Const FILE_ATTRIBUTE_NORMAL As Long = &H80 Const FILE_FLAG_NO_BUFFERING As Long = &H20000000
Const FILE_DEVICE_CD_ROM As Long = &H2 Const FILE_DEVICE_DVD As Long = &H33
Private Declare Function GetDriveType Lib "kernel32.dll" Alias "GetDriveTypeA" _ (ByVal nDrive As String) As Long Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _ (lbVersionInfirmation As OSVERSIONINFO) As Long
Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type
Private Enum STORAGE_MEDIA_TYPE DDS_4mm = &H20 MiniQic Travan QIC MP_8mm AME_8mm AIT1_8mm DLT NCTP IBM_3480 IBM_3490E IBM_Magstar_3590 IBM_Magstar_MP STK_DATA_D3 SONY_DTF DV_6mm DMI SONY_D2 CLEANER_CARTRIDGE CD_ROM CD_R CD_RW DVD_ROM DVD_R DVD_RW MO_3_RW MO_5_WO MO_5_RW MO_5_LIMDOW PC_5_WO PC_5_RW PD_5_RW ABL_5_WO PINNACLE_APEX_5_RW SONY_12_WO PHILIPS_12_WO HITACHI_12_WO CYGNET_12_WO KODAK_14_WO MO_NFR_525 NIKON_12_RW IOMEGA_ZIP IOMEGA_JAZ SYQUEST_EZ135 SYQUEST_EZFLYER SYQUEST_SYJET AVATAR_F2 MP2_8mm DST_S DST_M DST_L VXATape_1 VXATape_2 STK_9840 LTO_Ultrium LTO_Accelis DVD_RAM AIT_8mm ADR_1 ADR_2 End Enum
Private Enum DriveType UNKNOWN = 0 NO_ROOT_DIR REMOVABLE FIXED REMOTE DVDORCDROM RAMDISK DVD CDROM End Enum
Const DRIVE_CDROM = 5 Const DRIVE_FIXED = 3 Const DRIVE_RAMDISK = 6 Const DRIVE_REMOTE = 4 Const DRIVE_REMOVABLE = 2 Const DRIVE_NO_ROOT_DIR = 1 Const DRIVE_UNKNOWN = 0
Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, _ ByVal dwIoControlCode As Long, lpInBuffer As Any, _ ByVal nInBufferSize As Long, lpOutBuffer As Any, _ ByVal nOutBufferSize As Long, lpBytesReturned As Long, _ lpOverlapped As Any) As Long Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal _ lpFileName As String, ByVal dwDesiredAccess As Long, _ ByVal dwShareMode As Long, lpSecurityAttributes As Long, _ ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, _ ByVal hTemplateFile As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As _ Long
Private Function GetDriveTypeEx(DriveLetter As String) As DriveType Dim OS As String OS = GetOsVersion() If Len(Trim$(DriveLetter)) <> 2 And Right$(Trim$(DriveLetter), _ 1) <> ":" Then MsgBox "Please enter the drive letter and a colon." Else GetDriveTypeEx = GetDriveType(Trim$(DriveLetter)) If GetDriveTypeEx = DVDORCDROM And (OS = "Win2K" Or OS = "WinXP") Then Dim mediaTypes As GET_MEDIA_TYPES Dim status As Long Dim returned As Long Dim hDevice As Long Dim mynull As Long hDevice = CreateFile("\\.\" & UCase$(Trim$(DriveLetter)), _ GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, _ mynull, OPEN_EXISTING, 0, mynull) If hDevice <> INVALID_HANDLE_VALUE Then status = DeviceIoControl(hDevice, _ IOCTL_STORAGE_GET_MEDIA_TYPES_EX, mynull, 0, mediaTypes, _ 2048, returned, ByVal 0) If status = 0 Then MsgBox "DRIVER ERROR" GetDriveTypeEx = UNKNOWN Exit Function Else If mediaTypes.DeviceType = FILE_DEVICE_CD_ROM Then MsgBox "CDROM" GetDriveTypeEx = CDROM ElseIf mediaTypes.DeviceType = FILE_DEVICE_DVD Then MsgBox "DVD" GetDriveTypeEx = DVD Else MsgBox "Unknown optical drive type" End If End If CloseHandle hDevice Else MsgBox "FILE ERROR" End If Else Select Case GetDriveTypeEx Case DVDORCDROM MsgBox "DVD or CDROM" Case FIXED MsgBox "FIXED" Case RAMDISK MsgBox "RAMDISK" Case REMOTE MsgBox "REMOTE" Case REMOVABLE MsgBox "REMOVABLE" Case NO_ROOT_DIR MsgBox "INVALID ROOT DIR" Case UNKNOWN MsgBox "UNKNOWN" End Select End If End If End Function
Function GetOsVersion() As String Dim lret As Long Dim osverinfo As OSVERSIONINFO
osverinfo.dwOSVersionInfoSize = Len(osverinfo)
lret = GetVersionEx(osverinfo)
If lret = 0 Then GetOsVersion = "unknown" Else Select Case osverinfo.dwPlatformId & "/" & osverinfo.dwMajorVersion & _ "/" & osverinfo.dwMinorVersion Case "1/4/0" GetOsVersion = "Win95" Case "1/4/10" GetOsVersion = "Win98" Case "1/4/90" GetOsVersion = "WinME" Case "2/3/51" GetOsVersion = "WinNT351" Case "2/4/0" GetOsVersion = "WinNT4" Case "2/5/0" GetOsVersion = "Win2K" Case "2/5/1" GetOsVersion = "WinXP" Case Else GetOsVersion = "Unsupported Version" End Select End If End Function |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|