ADSM-L

Re: How to find out all drives in NT2000 using command line? Thanks

2005-04-25 12:16:37
Subject: Re: How to find out all drives in NT2000 using command line? Thanks
From: Andrew Raibeck <storman AT US.IBM DOT COM>
To: ADSM-L AT VM.MARIST DOT EDU
Date: Mon, 25 Apr 2005 10:16:07 -0600

Hi Frank,

There is no command that I can think of that does this; you'd have to write a program or script to do it. Here are sample script and C++ program (they both do the same thing). If these are useful, tailor as you wish.

Regards,

Andy


WMI SCRIPT

' ListDrives.vbs
' Invoke by running
'
'    cscript ListDrives.vbs
'
' from an OS command prompt.
strComputer = "."

set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")

set disks = objWMIService.ExecQuery ("select * from Win32_LogicalDisk")

for each objDisk in disks
   select case objDisk.DriveType
      case 0
         ' I would not normally expect to see this.
         Wscript.Echo objDisk.DeviceID & " Unknown"
      case 1
         Wscript.Echo objDisk.DeviceID & " Invalid root path"
      case 2
         Wscript.Echo objDisk.DeviceID & " Removable"
      case 3
         Wscript.Echo objDisk.DeviceID & " Fixed"
      case 4
         Wscript.Echo objDisk.DeviceID & " Remote"
      case 5
         Wscript.Echo objDisk.DeviceID & " CD-ROM"
      case 6
         Wscript.Echo objDisk.DeviceID & " RAM disk"
      case Else
         ' I would not normally expect to see this.
         Wscript.Echo objDisk.DeviceID & " ??????"
   end select
next




C++ PROGRAM

/*
 ListDrive.cpp

 Compiled with Visual Studio .Net 2003 from an OS prompt as follows:

   cl /GX /Zi /O1 ListDrives.cpp /link /debug
*/
#include <windows.h>
#include <cstdio>
#include <cmath>
#include <iostream>

using namespace std;

int main()
{
   char  driveLetter[] = "*:\\";
   DWORD drives        = GetLogicalDrives();
   DWORD bit           = 0;

   if (!drives)
   {
      cout << "ERROR: GetLogicalDrives() failed with rc "
           << GetLastError() << endl;
      return -1;
   }

   for (int i = 0, bit = 1; i != 26; i++, bit *= 2)
   {
      if (drives & bit)
      {
         cout << char('A' + i) << ": ";
         driveLetter[0] = 'A' + i;

         switch (GetDriveType(driveLetter))
         {
            case DRIVE_UNKNOWN:
               // I would not normally expect to see this.
               cout << "Unknown";
               break;
            case DRIVE_NO_ROOT_DIR:
               cout << "Invalid root path";
               break;
            case DRIVE_REMOVABLE:
               cout << "Removable";
               break;
            case DRIVE_FIXED:
               cout << "Fixed";
               break;
            case DRIVE_REMOTE:
               cout << "Remote";
               break;
            case DRIVE_CDROM:
               cout << "CD-ROM";
               break;
            case DRIVE_RAMDISK:
               cout << "RAM disk";
               break;
            default:
               // I would not normally expect to see this.
               cout << "??????";
               break;
         }   // switch (...)

         cout << endl;
      }   // if (drives & bit)
   }   // for (...)

   cout << endl;

   return 0;
}


Regards,

Andy

Andy Raibeck
IBM Software Group
Tivoli Storage Manager Client Development
Internal Notes e-mail: Andrew Raibeck/Tucson/IBM@IBMUS
Internet e-mail: storman AT us.ibm DOT com

The only dumb question is the one that goes unasked.
The command line is your friend.
"Good enough" is the enemy of excellence.


"ADSM: Dist Stor Manager" <ADSM-L AT VM.MARIST DOT EDU> wrote on 2005-04-22 14:05:23:

> Frank Tsao
> Frank.Tsao AT sce DOT com
> PAX 25803, 626-302-5803
> FAX 626-302-7131

Attachment: ListDrives.cpp
Description: Binary data


Attachment ListDrives.vbs contains a potentially harmful file type extension 
and was removed in accordance with IBM IT content security practices.
<Prev in Thread] Current Thread [Next in Thread>