Results 1 to 8 of 8

Thread: How do I access drive/volume information (DiskInfo)

  1. #1

    How do I access drive/volume information (DiskInfo)

    I suppose that the topic title is relatively self-explanatory, I was wondering if there are any examples of how I may list drives and parse them in such a way as to detect only fixed removable network cd-rom etc. Also I'd like to be able to check a drive/volume's file system; i.e. FAT[nn] NTFS, CDFS etc.

    In VB/VBS I believe that the filesystemobject is used for this information but I couldn't find something similar in my quick scan over the included modules and scripts.

    Thank you for any information or guidance on this 'my first question'!

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: How do I access drive/volume information

    Hi Jon.

    The following is one possible way to get the list of drives:

     '---Needed modules
     uses "CONSOLE"
    
     '---API declares needed by the script
     DECLARE FUNCTION GetLogicalDriveStrings LIB "KERNEL32.DLL" ALIAS "GetLogicalDriveStringsA" (BYVAL nBufferLength AS DWORD,BYVAL lpBuffer AS DWORD) AS DWORD
    
     '----------------------------------------------------------------------------
     SUB Disk_GetList(byref DiskList() as string)
     '----------------------------------------------------------------------------
    
      '---A buffer big enough to contains the list of drives separated by a NULL char
      DIM DriveString As STRING * 512
     
      '---Get the list of drives
      GetLogicalDriveStrings(len(DriveString), STRPTR(DriveString))
    
      '---Fill the array with the found drives
      SPLIT(DriveString, chr$(0) , DiskList)
     
     END SUB
    
     dim Disks() as string   '---Define an empty array
     Disk_GetList(Disks)    '---Fill the array with the drive found
     
     '---Printout results
     printl "Found the following drives"
     for Counter AS LONG = 1 to ubound(Disks())
      printl Counter, Disks(Counter)
     next
    
     printL "---All done. Press a key when done---" 
     waitkey
    
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: How do I access drive/volume information

    Here is another way,

    using WMI. Retrieves installed drives and their filesystems.

    uses "Console" ' -- To be able to work with console
    USES "WMI"   ' -- To be able to manage WMI for hardware queries
    USES "OS"   ' -- To be able to retrieve PC name 
    
    ' -- Variables
    dim driveLabels as string 
    dim driveName as string
    dim d as long
    
    driveLabels = GetInfoOnDrives("DeviceID", "") ' -- Return info separated by tabelators
    printl driveLabels
    
    ' -- Go through all driveLabels and get their file system
    for d = 1 to parsecount(driveLabels, $TAB)
    
     ' -- Retrieve just one drive label from tabelator delimited list
     driveName = PARSE$(driveLabels, $TAB, d)
     
     ' -- Put out formatted text
     
     printL "Drive " + driveName + " has " + GetInfoOnDrives("FileSystem", "DeviceID='" + driveName + "'") + " file system"
     
    next
    
    ' -- Wait for any key before program ends
    waitkey
    
    ' -- End program ( optional )
    stop
    
    
    ' --
    ' -- Auxiliary function to use WMI interface, you can ignore it and simply use it :)
    ' --
    
    function GetInfoOnDrives( Feature as string, Condition as string ) as string
    
     local sBuffer as string = WMI_GetData(OS_GetComputerName, "", "", "", "Win32_LogicalDisk", Condition, Feature )
    
     local sLine() as string
     local nLines as long
    
     local OutString as string
    
     local i as long
     
     ' -- WMI function returns big string, following will create array which can be scaned line by line
     nLines = parse(sBuffer, sLine , $CRLF)
     
     ' -- We go through all lines and retrieve needed values 
     for i = 1 to nLines
      if instr(sLine(i), Feature) > 0 then OutString += PARSE$(sLine(i), "=", 2) + $TAB
     next 
     
     OutString = rtrim$(OutString, $TAB) ' -- Remove last TAB
     
     function = OutString
     
    end function
    

    Hope you will find it useful,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #4

    Re: How do I access drive/volume information

    Thank you both, I'm especially happy that my first question attracted a positive response as opposed to a quick RTFM or use the search facility.

    I was fairly certain there'd be a WMI method, I have Batch/WMIC scripts already which perform these functions, so Psch's example should help me better understand the way this language works!

    In the meantime however, because I've never used a language which can call API's I'm more intrigued by the ErosOlmi response and will now spend some time playing around with my script until I have something like I intended in the first instance.

    Thank you for inserting comments too, it's something I've rarely done but now I'm learning I've come to realize exactly how important they can be.

    You'll no doubt be hearing from me again soon!

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: How do I access drive/volume information

    Jon,

    I'm pretty sure you will never get a RTFM response in thinBasic forum (well, there can be a limit but very high ).

    Regarding thinBasic, it has full access to all Windows API. You just need to know how the API is declared and than use it like a normal function. So you have a big arsenal to play with. In many cases to simplify things, we have incorporated some API into native language functions or in some cases into complete thinBasic modules (special DLLs that add a set of new language functionalities automatically loaded at runtime). WMI is just one of those modules. We didn't develop all WMI functionalities but just the basis are able to help a lot.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: How do I access drive/volume information

    Also your request let me recall that we didn't developed much native functions about drives.
    Maybe we can do something for next thinBasic release. We can extend FILE module to work also on Disks other than files and directories.


    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: How do I access drive/volume information

    Attached a latest example in a form of a thinBasic executable. The attached example performs some new features that will be present in next thinBasic release like passing UDT elements BYREF to external DLLs (for example API). For this reason you cannot execute it with your current thinBasic so I have attached it as executable (and source code, just to haver a look).

    Attention: in case you have mounted a logical network disk that is currently offline, it can takes few seconds before returning info.

    Ciao
    Eros
    Attached Images Attached Images
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  8. #8
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: How do I access drive/volume information

    Very cool example Eros,

    only problem ( kind of GPF ) it has occurs when I try to get info from empty floppy drive ( I know it is old garbage, but I keep it for nostalgic purposes ).


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Similar Threads

  1. mp math and how to access variables in a dll
    By jack in forum Software discussion
    Replies: 3
    Last Post: 20-08-2011, 22:16
  2. Attachment Access
    By John Spikowski in forum Shout Box Area
    Replies: 1
    Last Post: 27-07-2011, 07:12
  3. Replies: 8
    Last Post: 14-01-2010, 04:56

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

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