Results 1 to 7 of 7

Thread: How to detect how many drives that a computer has ?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    Malaysia
    Posts
    9

    Post

    Hi,

    I'm trying to build a directory selection Treeview, but I having problem detecting all the available drives from a computer, i.e, how would I know that a computer has 4 hard drive and 3 floppy drive, not to mention that it might have another 2 zip drive and 1 CD-Rom....

    And, is there any way I can get the directory of the Desktop ? I found out that on some system and for some reason their directory was not "C:\Windows\Desktop". This is because I need to put a "My Computer" Icon on the top of the TreeView as a node.

    Oh... can all of the problem mentions above be solve with some API call or I just need to download some fancy OCX or ActiveX control ?

    Well, thanks for reading this, and thanks again if you halp me out. Have a nice day(or night)


    Hank
    ----
    A computer programmer, is the soul creators, for computers.

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Post

    You asked this before didn't you!?

    Why don't you download the fancy OCX from the web site URL that was given to you on the last post. I did - it's really good. You just slap it on a form and your ready to whirl!

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    Malaysia
    Posts
    9

    Post

    Oh... miss that out... hehe Thanks for telling me.


    Hank
    ----
    A computer programmers, is that soul creator, for computers.

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    In case in the true spirit of programming you're still interested in how you would have done it, here's an example I put together, just add a Listbox to a Form..
    Code:
    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()
        Dim sDrives As String
        Dim sDrive As String
        
        sDrives = Space(255)
        sDrives = Left$(sDrives, GetLogicalDriveStrings(255, sDrives))
        While Len(sDrives)
            sDrive = UCase(Left$(sDrives, 3) & Space(10))
            sDrives = Mid$(sDrives, 5)
            Select Case GetDriveType(Trim(sDrive))
            Case DRIVE_CDROM
                sDrive = sDrive & "CD-ROM"
            Case DRIVE_FIXED
                sDrive = sDrive & "HDD (Fixed)"
            Case DRIVE_RAMDISK
                sDrive = sDrive & "RAM Disk"
            Case DRIVE_REMOTE
                sDrive = sDrive & "Remote (Network)"
            Case DRIVE_REMOVABLE
                sDrive = sDrive & "Removable (Diskette)"
            Case Else
                sDrive = sDrive & "Unknown"
            End Select
            List1.AddItem sDrive
        Wend
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    Malaysia
    Posts
    9

    Post

    Hi,

    Thanks Aaron, I've been trying to cut down my program size with less OCX, so I think I'll go for program one Folder TreeView myself, beside, the process is fun.

    Oh... but no one answer my question on how to I detect where is the Desktop location, I found out that not all system has it at "C:\Windows\Desktop\"

    So... anyone please help...

    Hank
    ----
    A computer programmer, is the soul creators, for computers.

  6. #6
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Sure. To get the Desktop folder path, use this:

    Code:
    Private Const CSIDL_DESKTOP = &H0
    Private Const MAX_PATH = 255
    Private Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As Long
    Private Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As Long
    
    Public Function GetDesktopFolderPath(ByVal pHwnd As Long) As String
        Dim lReturn As Long
        Dim lPidl   As Long
        Dim lPath   As Long
        Dim sPath   As String
    
        sPath = Space$(MAX_PATH)
        lReturn = SHGetSpecialFolderLocation(pHwnd, CSIDL_DESKTOP, lPidl)  ' Get lPidl for Id...
        If lReturn = 0 Then                                    ' If success is 0
            lReturn = SHGetPathFromIDList(lPidl, sPath)        '   Get Path from Item Id List
            If lReturn = 1 Then                                '   If success is 1
                sPath = Left(sPath, InStr(sPath, vbNullChar) - 1)             '     Fix path string
                GetDesktopFolderPath = sPath                    '     Return Desktop path
            End If
        End If
    End Function
    Then you can call this function to get the path of the desktop folder:


    Dim strPath As String

    strPath = GetDesktopFolderPath(Me.Hwnd)


    strPath now holds the path to the Desktop.

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

    Serge

    Programmer Analyst
    [email protected]
    [email protected]
    ICQ#: 51055819



    [This message has been edited by Serge (edited 02-01-2000).]

  7. #7
    Member
    Join Date
    Apr 1999
    Posts
    38

    Post

    if you want to use a 'Browse for folder'-dialog box, then check out the following URL:
    http://www.vbsquare.com/tips/tip180.html

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