-
July 6th, 2001, 06:32 AM
#1
Urgent !! How many Drives present in a system
Hi all
Can any one tell me which are the drives present in the System like(C: , d: etc).
I think the information must be present in registry but I don't know the path or If you know any alternative
Thanx n Regards
Rohit
-
July 6th, 2001, 06:41 AM
#2
Re: Urgent !! How many Drives present in a system
You may try this...
#define NUMBER_OF_DRIVES 26
int iKindOfDrive;
for(int iDrive = 0; iDrive< NUMBER_OF_DRIVES;iDrive++ )
{
CString sDriveName
sDriveName.Format("%c:",(iDrive + 'A'));
iKindOfDrive=GetDriveType(sDriveName);
//you have the info of your drive in iKindOfDrive
//if iKindOfDrive==1 no drive with this character
}
Hope it helps...
Toni
-
July 6th, 2001, 06:54 AM
#3
Re: Urgent !! How many Drives present in a system
Use GetLogicalDriveStrings() to return a buffer full of null terminated drive letters.
Such as "c:\0d:\0...z:\0" etc...
You can then use GotVolumeInformation() and GetDriveType() to gain further information on what kind of drive it is, whether it is local/network or whether it is available etc ...
Here is a section of code which i use to fill a CDirTreeCtrl (it's a custom class found on codeguru for showing files/directories in an explorer style tree ctrl). You won't be able to use it 'straight out of the box', as i am calling other class member functions within the code which i have not included here, but it will hopefully give you some idea on how to use the functions you need ...
BOOL CDirTreeCtrl:isplayDrives()
{
//
// Displaying the Availible Drives on this PC
// This are the First Items in the TreeCtrl
//
CDriveCheckDlg *pDlg = new CDriveCheckDlg;
pDlg->Create(IDD_DIALOG_DRIVE_CHECK);
pDlg->ShowWindow(SW_SHOW);
DeleteAllItems();
char szDrives[128];
char *pDrive;
if(!GetLogicalDriveStrings( sizeof(szDrives), szDrives))
{
m_strError = "Error Getting Logical DriveStrings!";
return FALSE;
}
CString s;
pDrive = szDrives;
//TCHAR lpBuf[64];
while(*pDrive)
{
// GetVolumeInformation(pDrive, lpBuf, 64, NULL, NULL, NULL, NULL, NULL);
s.Format("Checking drive %s ...", pDrive);
pDlg->m_staticText.SetWindowText(s);
pDlg->m_staticText.CenterWindow();
// LOG((LPCTSTR)s);
UINT nRet = GetDriveType(pDrive);
switch(nRet)
{
// treat these as local hard disks and just check for subordinate files
case DRIVE_UNKNOWN:
case DRIVE_NO_ROOT_DIR:
case DRIVE_REMOVABLE:
case DRIVE_FIXED:
case DRIVE_CDROM:
case DRIVE_RAMDISK:
//case DRIVE_REMOTE:
s.Format("Drive [%s] is a local disk ...", pDrive);
LOG((LPCTSTR)s);
if(CheckDriveForFiles(pDrive))
{
// CString strDrive;
// strDrive = pDrive;
// strDrive += " ";
// strDrive += lpBuf;
HTREEITEM hParent = AddItem(TVI_ROOT, pDrive);
InsertItem("", 0, 0, hParent);
}
else
{
s.Format("Drive [%s] contains no files, or is an unavailable network resource. Excluding from file tree.", pDrive);
LOG((LPCTSTR)s);
}
break;
// this is a network drive - determine whether it is available
case DRIVE_REMOTE:
s.Format("Drive [%s] is a mapped network drive ...", pDrive);
LOG((LPCTSTR)s);
TCHAR tBuf[1000] = {0};
TCHAR errBuf[1000] = {0};
TCHAR nameBuf[1000] = {0};
DWORD dwUniSz = 1000;
UNIVERSAL_NAME_INFO *pUni = (UNIVERSAL_NAME_INFO *)tBuf;
DWORD dwRet = WNetGetUniversalName(pDrive, // pointer to drive-based path for a network resource
UNIVERSAL_NAME_INFO_LEVEL, // specifies form of universal name to be obtained
(LPVOID)tBuf, // pointer to buffer that receives universal name data structure 0);//&dwUniSz );// pointer to variable that specifies size of buffer
&dwUniSz); // pointer to dword holding size of buffer
// if drive is available, and contains files
if(dwRet == NO_ERROR && CheckDriveForFiles(pDrive))
{
// CString strDrive;
// strDrive = pDrive;
// strDrive += " ";
// strDrive += lpBuf;
HTREEITEM hParent = AddItem(TVI_ROOT, pDrive);
InsertItem("", 0, 0, hParent);
}
else
{
if(dwRet != NO_ERROR)
{
WNetGetLastError( &dwUniSz,// pointer to error code
errBuf, // pointer to string describing error
1000, // size of description buffer, in characters
nameBuf, // pointer to buffer for provider name
1000 // size of provider name buffer
);
switch(dwRet)
{
case ERROR_INVALID_ADDRESS:
s.Format("Error 'invalid address' accessing mapped drive [%s]. Excluding from file tree.", pDrive);
break;
case ERROR_BAD_DEVICE:
s.Format("Error 'bad device' accessing mapped drive [%s]. Excluding from file tree.", pDrive);
break;
case ERROR_CONNECTION_UNAVAIL:
s.Format("Error 'connection unavailable' accessing mapped drive [%s]. Excluding from file tree.", pDrive);
break;
case ERROR_EXTENDED_ERROR:
s.Format("Error 'extended error' accessing mapped drive [%s]. Excluding from file tree.", pDrive);
break;
case ERROR_MORE_DATA:
s.Format("Error 'more data' accessing mapped drive [%s]. Excluding from file tree.", pDrive);
break;
case ERROR_NOT_SUPPORTED:
s.Format("Error 'not supported' accessing mapped drive [%s]. Excluding from file tree.", pDrive);
break;
case ERROR_NO_NET_OR_BAD_PATH:
s.Format("Error 'no network or bad path' accessing mapped drive [%s]. Excluding from file tree.", pDrive);
break;
case ERROR_NO_NETWORK:
s.Format("Error 'no network' accessing mapped drive [%s]. Excluding from file tree.", pDrive);
break;
case ERROR_NOT_CONNECTED:
s.Format("Error 'not connected' accessing mapped drive [%s]. Excluding from file tree.", pDrive);
break;
default:
s.Format("Error 'unspecified error' accessing mapped drive [%s]. Excluding from file tree.", pDrive);
break;
}
LOG((LPCTSTR)s);
}
else
{
s.Format("Drive [%s] contains no files, or is an unavailable network resource. Excluding from file tree.", pDrive);
LOG((LPCTSTR)s);
}
}
}
pDrive += strlen(pDrive) + 1;
}
pDlg->ShowWindow(SW_HIDE);
delete pDlg;
return TRUE;
}
I hope this helps.
Jase
<no witty trailer supplied>
Jase
www.slideshowdesktop.com
View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows....
-
July 6th, 2001, 09:50 AM
#4
Re: Urgent !! How many Drives present in a system
To get information about logical drives you can use this piece of code.
void GetDriveInfo()
{
char *szInfo,szName[80];
char szCurrentDrive[MAX_PATH];
UINT nDrives, nDriveType;
DWORD dwLogicalDrives;
// Get the all the logical drives. Function will return a bit mask of the logical
// drives. Bits are set if the corresponding drives are available. Bit 0 represents
// drive A, bit 2 is drive B and so on.
dwLogicalDrives = GetLogicalDrives ();
for (nDrives = 0; nDrives < 32; nDrives ++)
{
if (dwLogicalDrives & (1 << nDrives))
{
memset(szName,0,80);
wsprintf (szCurrentDrive, "%c", nDrives + 'A');
strcpy (szName, szCurrentDrive);
strcat (szCurrentDrive, ":\\");
// Get the drive type.
nDriveType = GetDriveType (szCurrentDrive);
switch ( nDriveType)
{
case DRIVE_UNKNOWN :
szInfo = "Unknown\r\n";
break;
case DRIVE_NO_ROOT_DIR :
szInfo = "No Root Directory\r\n" ;
break;
case DRIVE_REMOVABLE :
szInfo = "Floppy/Removable\r\n";
break;
case DRIVE_FIXED :
szInfo = "Hard Disk\r\n";
break;
case DRIVE_REMOTE :
szInfo = "Network Drive\r\n";
break;
case DRIVE_CDROM :
szInfo = "CD-ROM Drive\r\n";
break;
case DRIVE_RAMDISK:
szInfo = "RAM Disk \r\n";
break;
}
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|