Results 1 to 14 of 14

Thread: CD Rom Drive?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Posts
    237

    CD Rom Drive?

    How I can make my program perform certain functions...performing those functions will depend whether the program is running from CD ROM or C Drive... it should perform certain function if it is running from CD-ROM Drive....and it will perfrom other function if it is running from C Drive....

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    So, what do you want to check...is there a CD in the drive or not?

    And, if so, is the CD mine?

  3. #3
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    VB Code:
    1. Dim obj As New FileSystemObject
    2. Dim drv As Drive
    3.  
    4. Private Sub Command1_Click()
    5. Set drv = obj.GetDrive(Mid(App.Path, 1, 3))
    6. MsgBox drv.DriveType
    7. End Sub

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  4. #4
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Try this:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetVolumeInformation Lib _
    4.     "kernel32.dll" Alias "GetVolumeInformationA" (ByVal _
    5.     lpRootPathName As String, ByVal lpVolumeNameBuffer As _
    6.     String, ByVal nVolumeNameSize As Integer, _
    7.     lpVolumeSerialNumber As Long, lpMaximumComponentLength _
    8.     As Long, lpFileSystemFlags As Long, ByVal _
    9.     lpFileSystemNameBuffer As String, ByVal _
    10.     nFileSystemNameSize As Long) As Long
    11.  
    12. Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
    13. Private Const DRIVE_CDROM = 5
    14. Private Const DRIVE_FIXED = 3
    15. Private Const DRIVE_RAMDISK = 6
    16. Private Const DRIVE_REMOTE = 4
    17. Private Const DRIVE_REMOVABLE = 2
    18.  
    19. Private Sub Form_Load()
    20.     MsgBox "A:\" & DriveType("A:\")
    21.     MsgBox "C:\" & DriveType("C:\")
    22.     MsgBox "D:\" & DriveType("D:\")
    23.     MsgBox "E:\" & DriveType("E:\")
    24.     MsgBox "F:\" & DriveType("F:\")
    25.     MsgBox "G:\" & DriveType("G:\")
    26. End Sub
    27.  
    28. Public Function DriveType(Drive As String) As String
    29.     Dim Tipo As Integer
    30.    
    31.     Tipo = GetDriveType(Drive)
    32.     Select Case Tipo
    33.         Case DRIVE_CDROM
    34.             DriveType = "CD-ROM"
    35.         Case DRIVE_FIXED
    36.             DriveType = "Fixed"
    37.         Case DRIVE_RAMDISK
    38.             DriveType = "RAM Disk"
    39.         Case DRIVE_REMOTE
    40.             DriveType = "Remote Disk"
    41.         Case DRIVE_REMOVABLE
    42.             DriveType = "Removable"
    43.     End Select
    44. End Function
    45.  
    46. Public Function GetSerialNumber(strDrive As String, DiskLabel As String) As String
    47.     Dim SerialNum As Long
    48.     Dim Res As Long
    49.     Dim Temp1 As String
    50.     Dim Temp2 As String
    51.     Temp1 = String$(255, Chr$(0))
    52.     Temp2 = String$(255, Chr$(0))
    53.     Res = GetVolumeInformation(strDrive, Temp1, _
    54.     Len(Temp1), SerialNum, 0, 0, Temp2, Len(Temp2))
    55.     GetSerialNumber = Hex$(SerialNum)
    56.     GetSerialNumber = String$(8 - Len(GetSerialNumber), "0") + GetSerialNumber
    57.     GetSerialNumber = Left$(GetSerialNumber, 4) + "-" + Mid$(GetSerialNumber, 5)
    58.    
    59.     DiskLabel = Trim0(Temp1)
    60. End Function
    61.  
    62. Public Function Trim0(ByVal e0 As String)
    63.     Dim i As Integer
    64.     For i = Len(e0) To 1 Step -1
    65.         If Mid$(e0, i, 1) <> Chr$(0) Then Exit For
    66.     Next i
    67.     Trim0 = Left$(e0, i)
    68. End Function
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Posts
    237
    I wanna check which dirve the progaram is running from? is it running from C Drive or CD-ROM Drive..and accordingly I will build a code to perform certain function... thanks

  6. #6
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Private Declare Function GetDriveType Lib "kernel32" _
    2. Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
    3.  
    4. Private Const DRIVE_CDROM = 5
    5.  
    6. Private Sub Form_Load()
    7.     Dim tmpStr As String
    8.     tmpStr = Left(App.Path, 3)
    9.     If GetDriveType(tmpStr) = DRIVE_CDROM Then
    10.         'app is ran from cd...
    11.     Else
    12.         'app started from other device
    13.     End If
    14. End Sub
    -= a peet post =-

  7. #7
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by vb6-lover
    I wanna check which dirve the progaram is running from? is it running from C Drive or CD-ROM Drive..and accordingly I will build a code to perform certain function... thanks
    Peet gave you the answer...
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  8. #8
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    Peet, is there a difference (as far as execution and functionality goes) between

    Left("abcd",3) and Mid("abcd",1,3)

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  9. #9
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by KayJay
    Peet, is there a difference (as far as execution and functionality goes) between

    Left("abcd",3) and Mid("abcd",1,3)
    No
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  10. #10
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    Thanx

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  11. #11
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Originally posted by KayJay
    Peet, is there a difference (as far as execution and functionality goes) between

    Left("abcd",3) and Mid("abcd",1,3)
    No, and from what I can see your answer will do the job just as fine as what i suggested... its just me being very slow... I swear there were no answers to this thread when I started replying ... I'm getting old... *sob*
    -= a peet post =-

  12. #12
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    Same here.

    BTW for the record, I have finalized 3 deals and with no small part on your side. Half (Actually the full of one of the apps) my code for the apps I sold are with advice/sample/snippets/pointers from you, among other senior members on the Board

    Old, maybe but useful and effective nevertheless

    Thanx a lot

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  13. #13
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Same here.

    BTW for the record, I have finalized 3 deals and with no small part on your side. Half (Actually the full of one of the apps) my code for the apps I sold are with advice/sample/snippets/pointers from you, among other senior members on the Board

    Old, maybe but useful and effective nevertheless

    Thanx a lot
    whohoooo!

    if it wasn't for the arthritis and my bones being so old and brittle I'd do one of my old famous viking-cheerleader acts on the vbf coffee table! (its over there in the corner..the table...)
    -= a peet post =-

  14. #14
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849

    Talking

    Cheers

    and Good Luck with your Cheerleader dance!

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width