LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Disk Drive Information

Hi,

Is there a way to get a list of disk drives on a system along with their
properties? This would include floppy, hard, CD and USB drives.

Many thanks for any help.

George


0 Kudos
Message 1 of 3
(3,375 Views)
Hello George,

You would use WinSDK calls to return disk drive information and properties. The attached code returns the physical drives on your computer and their types. If you would like more in depth specs on your drives, take a look at the example program provided by Microsoft. This program returns adapter and device properties.


------------------------------>
#include windows.h>
#include ansi_c.h>
#include stdio.h>
#include cvirte.h>


int main (int argc, char *argv[])
{
char szBuffer[MAX_PATH+100];
int nDrive;
DWORD dwLogicalDrives = GetLogicalDrives();

for ( nDrive = 0; nDrive<32; nDrive++ )
{
if ( dwLogicalDrives & (1 << nDrive) )
{
UINT uType;

/* Get disk information.*/
sprintf(szBuffer, "%c:\\", nDrive+'A' );
uType = GetDriveType(szBuffer);

/* display information.*/
sprintf(&szBuffer[3], " Id: %u, Type: %s ", uType,
(uType == DRIVE_REMOVABLE) ? "FLOPPY" :
((uType == DRIVE_FIXED) ? "HARD DISK" :
((uType == DRIVE_REMOTE) ? "NETWORK" :
((uType == DRIVE_CDROM) ? "CDROM" :
(uType == DRIVE_RAMDISK) ? "RAMDISK" :
((uType == 1) ? "DOES NOT EXIST" :
"UNKNOWN DRIVE TYPE" ))))));
printf("%s\n", szBuffer);
}
}

if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */

return 0;
}

------------------------------>

Good luck!
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 2 of 3
(3,351 Views)
Hi Wendy,

Many thanks! That worked perfectly. (Maybe I'll get that raise at work now
:) )

Best regards,
George

"Wendy L" <x@no.email> wrote in message news:167602@exchange.ni.com...
Hello George,<br><br>You would use WinSDK calls to return disk drive
information and properties. The attached code returns the physical drives
on your computer and their types. If you would like more in depth specs on
your drives, take a look at the <a
href="http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q264203"
target=_blank>example program</a> provided by Microsoft. This program
returns adapter and device
properties.<br><br><br>------------------------------><br>#include
windows.h><br>#include ansi_c.h><br>#include stdio.h><br>#include
cvirte.h><br><br><br>int main (int argc, char *argv[])<br>{<br> char
szBuffer[MAX_PATH+100];<br> int nDrive;<br> DWORD dwLogicalDrives =
GetLogicalDrives();<br> <br> for ( nDrive = 0; nDrive<32; nDrive++ )<br>
{<br> if ( dwLogicalDrives & (1 << nDrive) )<br> {<br> UINT uType;<br> <br>
/* Get disk information.*/<br> sprintf(szBuffer, "%c:\\", nDrive+'A' );<br>
uType = GetDriveType(szBuffer);<br><br> /* display information.*/<br>
sprintf(&szBuffer[3], " Id: %u, Type: %s ", uType, <br> (uType ==
DRIVE_REMOVABLE) ? "FLOPPY" :<br> ((uType == DRIVE_FIXED) ? "HARD DISK"
:<br> ((uType == DRIVE_REMOTE) ? "NETWORK" :<br> ((uType == DRIVE_CDROM) ?
"CDROM" :<br> (uType == DRIVE_RAMDISK) ? "RAMDISK" :<br> ((uType == 1) ?
"DOES NOT EXIST" :<br> "UNKNOWN DRIVE TYPE" ))))));
<br> printf("%s\n", szBuffer);<br> }<br> }<br><br> if (InitCVIRTE (0, argv,
0) == 0)<br> return -1; /* out of memory */<br><br>return
0;<br>}<br><br>------------------------------><br><br>Good luck!


0 Kudos
Message 3 of 3
(3,346 Views)