PDA

View Full Version : سی دی رام



mr_esmaily
شنبه 15 شهریور 1382, 11:10 صبح
چگونه می توان نام درایو سی دی رام و دیگر درایوهای سی دی را تشخیس داد؟ :wink:

M-Gheibi
یک شنبه 16 شهریور 1382, 03:10 صبح
اینم یک مثال کامل :

mr_esmaily
یک شنبه 16 شهریور 1382, 07:13 صبح
تشکر 8)

Danial_Yousefi
دوشنبه 18 مهر 1384, 16:22 عصر
Private Declare Function GetVersion Lib "kernel32" () As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
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 CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const INVALID_HANDLE_VALUE = -1
Private Const OPEN_EXISTING = 3
Private Const FILE_FLAG_DELETE_ON_CLOSE = 67108864
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const IOCTL_STORAGE_EJECT_MEDIA = 2967560
Private Const VWIN32_DIOC_DOS_IOCTL = 1
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 Type DIOC_REGISTERS
reg_EBX As Long
reg_EDX As Long
reg_ECX As Long
reg_EAX As Long
reg_EDI As Long
reg_ESI As Long
reg_Flags As Long
End Type

Private Sub Combo1_Change()
Label2.Caption = Combo1.Text

End Sub

Private Sub Combo1_Click()
Label2.Caption = Combo1.Text

End Sub

Private Sub Command1_Click()
Dim hDrive As Long, DummyReturnedBytes As Long
Dim EjectDrive As String, DriveLetterAndColon As String
Dim RawStuff As DIOC_REGISTERS
EjectDrive = Label2.Caption
If Len(EjectDrive) Then 'Confirm the user didn't cancel
DriveLetterAndColon = UCase(Left$(EjectDrive & ":", 2)) 'Make it all caps for easy interpretation
If GetVersion >= 0 Then 'We are running Windows NT/2000
hDrive = CreateFile("\\.\" & DriveLetterAndColon, GENERIC_READ Or GENERIC_WRITE, 0, ByVal 0, OPEN_EXISTING, 0, 0)
If hDrive <> INVALID_HANDLE_VALUE Then
'Eject media!
Call DeviceIoControl(hDrive, IOCTL_STORAGE_EJECT_MEDIA, 0, 0, 0, 0, DummyReturnedBytes, ByVal 0)
Call CloseHandle(hDrive) 'Clean up after ourselves
End If
Else 'We are running Win9x/Me
hDrive = CreateFile("\\.\VWIN32", 0, 0, ByVal 0, 0, FILE_FLAG_DELETE_ON_CLOSE, 0)
If hDrive <> INVALID_HANDLE_VALUE Then
'Setup our raw registers to use Interrupt 21h Function 440Dh Minor Code 49h
RawStuff.reg_EAX = &H440D 'The function to use
RawStuff.reg_EBX = Asc(DriveLetterAndColon) - Asc("A") + 1 'The drive to do it on
RawStuff.reg_ECX = &H49 Or &H800 'The minor code of the function in the low byte of the low word and the device category of 8 in the high byte of the low word
'Eject media!
Call DeviceIoControl(hDrive, VWIN32_DIOC_DOS_IOCTL, RawStuff, LenB(RawStuff), RawStuff, LenB(RawStuff), DummyReturnedBytes, ByVal 0)
Call CloseHandle(hDrive) 'Clean up after ourselves
End If
End If
End If
End Sub

Private Sub Form_Load()

Me.AutoRedraw = True
'Get information about the C:\
Select Case GetDriveType(Label2.Caption)
Case 2
Label1.Caption = "Floppy Disk"
Case 3
Label1.Caption = "Drive Fixed"
Case Is = 4
Label1.Caption = "Remote"
Case Is = 5
Label1.Caption = "Cd-Rom"
Case Is = 6
Label1.Caption = "Ram disk"
Case Else
Label1.Caption = "Unrecognized"
End Select

Dim strSave As String
'Set the graphic mode to persistent
Me.AutoRedraw = True
'Create a buffer to store all the drives
strSave = String(255, Chr$(0))
'Get all the drives
ret& = GetLogicalDriveStrings(255, strSave)
'Extract the drives from the buffer and print them on the form
For ke = 1 To 100
If Left$(strSave, InStr(1, strSave, Chr$(0))) = Chr$(0) Then Exit For
Combo1.AddItem Left$(strSave, InStr(1, strSave, Chr$(0)) - 1)

strSave = Right$(strSave, Len(strSave) - InStr(1, strSave, Chr$(0)))
Next ke
End Sub

Private Sub Timer1_Timer()
Me.AutoRedraw = True
'Get information about the C:\
Select Case GetDriveType(Label2.Caption)
Case 2
Label1.Caption = "Floppy Disk"
Case 3
Label1.Caption = "Logical Hard Disk Partiotion"
Case Is = 4
Label1.Caption = "Remote"
Case Is = 5
Label1.Caption = "Cd-Rom"
Case Is = 6
Label1.Caption = "Ram disk"
Case Else
Label1.Caption = "Unrecognized"
End Select
If Label1.Caption = "Cd-Rom" Then
Command1.Enabled = True
Else
Command1.Enabled = False
End If
End Sub