Novell Home

Is this a CD-ROM drive

From Developer Community

Code to determine the status of a drive from a workstation: CD-ROM or not. Uses NWGetDriveStatus() to get this information.

Sample Code

#if !defined( N_PLAT_NLM)
#define N_PLAT_WNT
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef __MWERKS__
#pragma ANSI_strict off
#endif
#include <nwcalls.h>
#include <nwclxcon.h>
#ifdef __MWERKS__
#pragma ANSI_strict reset
#endif

#if defined( __MWERKS__) && !defined( N_PLAT_NLM)
#define strupr(s) (_strupr(s),s) /* CW Pro 5.3 has a bug in _strupr */
#endif

int main( int argc, char* argv[]) {
   char const*    server_name;
#ifdef N_PLAT_NLM
   char const*    user_name;
   char const*    password;
#endif
   nuint16        driveNum;
   NWRCODE        rcode;
   NWCCODE        ccode;
   NWCONN_HANDLE  conn_handle;
   nuint16        status;
#ifdef N_PLAT_NLM
   if ( argc != 5) {
      printf( "Usage: %s <servername> <username> <password> <driveNum>\n", *argv);
#else
   if ( argc != 3) {
      printf( "Usage: %s <servername> <driveNum>\n", *argv);
#endif
      return EXIT_FAILURE;
   }
   server_name = strupr( *++argv);
#ifdef N_PLAT_NLM
   user_name   = strupr( *++argv);
   password    = strupr( *++argv);
#endif
   driveNum    = ( nuint16) atoi( *++argv);
   rcode = NWCCOpenConnByName( 0,
                               server_name,
                               NWCC_NAME_FORMAT_BIND,
                               NWCC_OPEN_LICENSED,
                               NWCC_TRAN_TYPE_WILD,
                               &conn_handle);
   if ( rcode != 0) {
      printf( "NWCCOpenConnByName failed, rcode = %x", rcode);
      return EXIT_FAILURE;
   }
#ifdef N_PLAT_NLM
   ccode = NWLoginToFileServer( conn_handle, user_name, OT_USER, password);
   if ( ccode != 0) {
      printf( "NWLoginToFileServer failed, ccode = %x", ccode);
      NWCCCloseConn( conn_handle);
      return EXIT_FAILURE;
   }
#endif
   ccode = NWGetDriveStatus( driveNum, NW_FORMAT_NETWARE, &status, NULL, NULL, NULL, NULL);
   if ( ccode != 0) {
      printf( "NWGetDriveStatus failed, ccode = %x", ccode);
      NWCCCloseConn( conn_handle);
      return EXIT_FAILURE;
   }
   printf( "drive #%u is%s a CD-ROM drive", driveNum, ( status & NW_CDROM_DRIVE) ? "" : " not");
   NWCCCloseConn( conn_handle);
   return EXIT_SUCCESS;
}

--Dmitry Mityugov

Novell® Making IT Work As One

© 2008 Novell, Inc. All Rights Reserved.