home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / lastdriv / lastdriv.c next >
C/C++ Source or Header  |  1989-02-16  |  3KB  |  77 lines

  1. /* LASTDRIV.C
  2. ** Version 1.0a
  3. ** Date: Jan 25 1988
  4. ** By:   Mike Watkins
  5. ** Modified : Feb 15 1989
  6. **
  7. ** Purpose: uses DOS function calls 14, 25 to determine what the current
  8. **          drive is and increment default drive to the lastdrive found.
  9. **
  10. ** Uses:    useful to determine that last valid network drive after
  11. **          logging off a network. Something like this batch file
  12. **          - call it NET.BAT
  13. **
  14. ** Example:      @echo off              (use the @ on DOS 3.3 to hide all)
  15. **               ipx
  16. **               net3
  17. **               lastdriv
  18. **               login
  19. **               l:
  20. **               menu [filename]
  21. **
  22. **/
  23.  
  24. /*       This program, however useless it is, is hearby released to the
  25. **                   public domain - Mike Watkins 02/15/89
  26. */
  27.  
  28. #include <dos.h>
  29.  
  30. union REGS inregs, outregs;
  31.  
  32. #define DosCall     0x21                        /* interupt 21H (dec 33) universal DOS functions */
  33. #define DosSetDrive 0x0e                        /* function 14 select current drive */
  34. #define DosGetDrive 0x19                        /* function 25 report current drive */
  35. #define DosWriteTTY 0x09                        /* dos write tty function */
  36.  
  37. int  drivenum = 0;                              /* last drive number */
  38.  
  39.  
  40. main()
  41. {                                               /* let 'em know were here! */
  42.  
  43.    WriteTTY("\n\rLastdriv  Version 1.0a (C) 1988 Software Suprizes\n\r$");
  44.  
  45.     inregs.h.ah = DosGetDrive;                  /* first find out current drive */
  46.     int86(DosCall, &inregs, &outregs);          /* outregs.h.al now equals current drive */
  47.     drivenum = outregs.h.al;
  48.  
  49.     inregs.h.ah = DosSetDrive;
  50.     inregs.h.dl = drivenum;
  51.     int86(DosCall, &inregs, &outregs);          /* outregs.h.al now = drive count */
  52.     drivenum = outregs.h.al;
  53.                                                 /* don't trust # of drives reported by last count. loop up to that */
  54.     LoopDrives();                               /* maximum, as some configurations leave holes in sequence         */
  55.     exit(0);
  56.                                                 /* DOS won't allow you to set drive that isn't there anyways       */
  57.  
  58. }       /* end of main */
  59.  
  60. LoopDrives()
  61. {
  62.     int i;
  63.     for (i=0; i <= drivenum - 1; i++){
  64.         inregs.h.ah = DosSetDrive;
  65.         inregs.h.dl = (i);                      /* drive numbering starts as A=0 B=1 ... */
  66.         int86(DosCall, &inregs, &outregs);
  67.         }
  68. }
  69.  
  70. WriteTTY(string)
  71. char *string;
  72. {
  73.     inregs.x.dx = string;                      /* use DosWriteTTY to print  - smaller code than printf */
  74.     inregs.h.ah = DosWriteTTY;
  75.     int86(DosCall, &inregs, &outregs);
  76. }
  77.