Click to See Complete Forum and Search --> : how do I determine a fix drive on a machine?
mrpatel
January 7th, 2003, 02:53 PM
Hi,
Is there any way to determine if a drive is a fixed drive or a network drive from a batch file or a perl script?
Thanks,
-Mehul
TheCPUWizard
January 7th, 2003, 03:34 PM
You can do it via API calls. One solution would be to write a simple program in something like C++ and return the result....
Andreas Masur
January 7th, 2003, 04:18 PM
The following is a solution for Microsoft operating systems...
#include <iostream>
using std::cout;
using std::endl;
// Get logical drives
DWORD dwLogicalDrives = ::GetLogicalDrives();
if(dwLogicalDrives)
{
for(int iCnt = 0; iCnt < 32; ++iCnt)
{
memset(szDriveRoot, 0, sizeof(szDriveRoot));
if(dwLogicalDrives & (1 << iCnt))
{
// Set drive root
sprintf(szDriveRoot, "%c:\\", iCnt + 'A');
// Determine partition type
UINT uiDriveType = ::GetDriveType(szDriveRoot);
switch(uiDriveType)
{
// Unknown
case DRIVE_UNKNOWN:
cout << "Partition " << szDriveRoot << " -> " << "Unknown" << endl;
break;
// Root path invalid
case DRIVE_NO_ROOT_DIR:
cout << "Partition " << szDriveRoot << " -> " << "Root path invalid"
<< endl;
break;
// Removable drive
case DRIVE_REMOVABLE:
cout << "Partition " << szDriveRoot << " -> " << "Removable drive"
<< endl;
break;
// Fixed drive
case DRIVE_FIXED:
cout << "Partition " << szDriveRoot << " -> " << "Fixed drive"
<< endl;
break;
// Network drive
case DRIVE_REMOTE:
cout << "Partition " << szDriveRoot << " -> " << "Network drive"
<< endl;
break;
// CD-ROM
case DRIVE_CDROM:
cout << "Partition " << szDriveRoot << " -> " << "CD-ROM"
<< endl;
break;
// RAM-Disk
case DRIVE_RAMDISK:
cout << "Partition " << szDriveRoot << " -> " << "RAM-Disk"
<< endl;
break;
}
}
}
}
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.