CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2001
    Posts
    13

    how do I determine a fix drive on a machine?

    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

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125
    You can do it via API calls. One solution would be to write a simple program in something like C++ and return the result....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    The following is a solution for Microsoft operating systems...
    Code:
    #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;
          }
        }
      }
    }

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

Featured