home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / asm / NETUTILS.ZIP / NETDRIVE.ASM next >
Encoding:
Assembly Source File  |  1991-06-19  |  8.2 KB  |  227 lines

  1. ; Program:  NETDRIVE
  2. ; Purpose:  Used to find the first network drive that contains a directory
  3. ;           called \LOGIN, then switches to that drive and directory and
  4. ;           saves the current drive letter into a DOS environment variable
  5. ;           named NETDRV.
  6. ; Author:   Dave Holden
  7. ; Date:     06-19-90
  8. ; Version:  1.1  06-19-91  Now checks for network drive up to drive Z:.  Used
  9. ;                          to stop looking at drive P:.
  10.  
  11. CODE      SEGMENT
  12.           ASSUME CS:CODE, DS:CODE, ES:CODE
  13.           ORG     100h
  14.           INCLUDE DOS.INC
  15. BEG:      JMP     START
  16.  
  17. STRING    DB      8 DUP (0)
  18. DRV       DB      "NETDRV="        ; Variable name
  19. LDRV      EQU     $-drv
  20. DRVCTR    DB      00                      ; Drive counter variable
  21. OLDDRV    DB      00                      ; Variable to save beginning drive
  22. PATH      DB      '\LOGIN',00             ; Login path (ASCIIZ string)
  23. ERR1      DB      "Invalid command",7,13,10,"$"
  24. ERR2      DB      "Out of environment space",7,13,10,"$"
  25. ERR3      DB      "Must have DOS Version 2.0 or higher",7,13,10,"$"
  26. NONET     DB      07h,0Dh,'Network shell not loaded!',0Dh,0Ah,24h
  27.  
  28. START:    MOV     AH,19h                  ; Get Current Drive function
  29.           INT     21h                     ; Returns drive number in AL
  30.           MOV     byte ptr CS:OLDDRV,AL   ; Save current drive
  31.  
  32.           MOV     AH,0DBh                 ; Get # of Logical Drives (Novell)
  33.           INT     21h
  34.           CMP     AL,00                   ; If AL=0 then shell not loaded,
  35.           JE      NETERR                  ; jump to NETERR
  36.           MOV     byte ptr CS:DRVCTR,AL   ; Otherwise, save logical drv count
  37.  
  38. CHGDR:    MOV     AH,0Eh                  ; Set Drive function
  39.           MOV     DL,byte ptr CS:DRVCTR      ; Move next drive (to try) into DL
  40.           INT     21h
  41.  
  42.           MOV     AX,CS                   ; Move Segment Address of PATH (CS)
  43.           MOV     DS,AX                   ;  into Data Segment (DS)
  44.           MOV     AH,3Bh                  ; Change Current Directory function
  45.           MOV     DX,offset CS:PATH       ; Set DX to offset of PATH
  46.           INT     21h
  47.  
  48.           JNC     SHELLOK                 ; Change Dir worked if Carry Flag=0
  49.           ADD     byte ptr CS:DRVCTR,1    ; Otherwise, inc Drive counter
  50.           CMP     byte ptr CS:DRVCTR,19h  ; If drive number is too high,
  51.           JG      RESTDR                  ;  restore drive and stop.
  52.           CLC
  53.           JMP     CHGDR                   ; If drive number is okay then try
  54.                                           ;  again.
  55. RESTDR:   MOV     AH,0Eh                  ; Set Drive function
  56.           MOV     DL,byte ptr CS:OLDDRV   ; Move previously saved drive to DL
  57.           INT     21h                     ; Restore drive
  58.           MOV     AH,4Ch                  ; Terminate function
  59.           MOV     AL,01h                  ; Set ERRORLEVEL to 1  (no net drive)
  60.           INT     21h
  61.  
  62. NETERR:   MOV     AX,CS                   ; Move Segment Address of PATH (CS)
  63.           MOV     DS,AX                   ; into Data Segment (DS)
  64.           MOV     AH,09h                  ; Print String function
  65.           MOV     DX,offset CS:NONET      ; Set DX to offset of NONET string
  66.           INT     21h
  67.           MOV     AH,4Ch                  ; Terminate function
  68.           MOV     AL,02h                  ; Set ERRORLEVEL to 2  (no shell)
  69.           INT     21h
  70.  
  71. SHELLOK:  mov     ax,cs                 ; Starting execution address
  72.       mov      ds,ax            ; Initialize data segment
  73.  
  74. DOSOK:    call    GetDrv                ; Call the GetDrv procedure
  75.           push    ax                    ; Save
  76.       push      es
  77.       call      DoEnviron        ; Put result in    environment string
  78.       or      ax,ax            ; Test for 0 before
  79.       pop      es            ;   restore
  80.       pop      ax
  81.           jz      DONE
  82.  
  83.       cmp      BYTE PTR es:[5Dh],'E'    ; Is it    Environment command
  84.           je      DONE                  ; Yes? Skip message
  85.  
  86. ERROR2:   @DispStr err2                 ; Error message
  87.  
  88. DONE:     @Exit   0                     ; Quit with AL as return code
  89.  
  90. ; Procedure Getdrv
  91. ; Purpose   Get    the current directory or drive
  92. ; Input        None
  93. ; Output    Current directory or drive in "string"; level or drive number in AX
  94.  
  95. Getdrv    PROC    NEAR
  96.       @GetDrv            ; Yes? Get drive
  97.       mov      ah,al            ; Copy
  98.       add      ah,'A'        ; Convert to drive letter
  99.       mov      string,ah        ; Put character    in string
  100.           mov     string[1],':'
  101.       cbw
  102.       ret
  103. Getdrv    ENDP
  104.  
  105. ; Procedure DoEnviron
  106. ; Purpose   Convert a string to    an environment variable
  107. ; Input        String in "string"
  108. ; Output    String in "WHAT" environment variable;
  109. ;          AX has 0 for success, nonzero for    failure
  110.  
  111. DoEnviron PROC
  112.       call      GetEnv        ; Get environment size,    length,    address
  113.       mov      dx,ax            ; Save size and    length
  114.       mov      bx,cx
  115.  
  116. ; Find "NETDRV="
  117.  
  118.       sub      di,di            ; Point    to start
  119.       sub      al,al            ; Search for zero
  120.           mov     si, OFFSET drv        ; Point source at "NETDRV="
  121. findwh:      repne      scasb            ; Search
  122.       cmp      BYTE PTR es:[di],0    ; If double null, end of environment
  123.       je      gotend
  124.       jcxz      noroom        ; Error    if not found
  125.       push      di            ; Save
  126.       push      cx
  127.           mov     si,OFFSET drv         ; Load address and length of "NETDRV"
  128.           mov     cx,ldrv               ;   for comparison
  129.       repe      cmpsb            ; Compare
  130.       mov      si,di            ; Make copy
  131.       pop      cx            ; Restore
  132.       pop      di
  133.       jnz      findwh
  134.  
  135. ; Find end of "NETDRV" variable
  136.  
  137.       xchg      di,si
  138.       repne      scasb            ; Find end of environment variable
  139.       xchg      si,di            ; Point    source to next variable
  140.  
  141. ; Calculate characters left to write
  142.  
  143.       mov      cx,bx            ; Load total characters
  144.       sub      cx,si            ; Subtract finished to get left
  145.  
  146. ; Move everything back to overwrite "NETDRV="
  147.  
  148. movenv:      push      ds            ; Save DS
  149.       mov      ax,es            ; Copy to ES
  150.       mov      ds,ax
  151.       rep      movsb            ; Copy
  152.       mov      BYTE PTR es:[di],0    ; Put null at end in case of error
  153.       pop      ds            ; Restore
  154.  
  155. ; Check    environment space
  156.  
  157. gotend:   mov     al,2                  ; Load length of string
  158.       sub      ah,ah            ; Clear    top
  159.           add     ax,ldrv               ; Add length of name
  160.       add      ax,di            ; Add position to get final length
  161.       cmp      ax,dx            ; Is it    longer than environment?
  162.       jge      noroom        ; Yes? Quit
  163.  
  164. ; Put netdrv= at end
  165.  
  166.           mov     si,OFFSET drv        ; Load address and length of drv
  167.           mov     cx,ldrv
  168.       rep      movsb
  169.  
  170. ; Put new string at end
  171.  
  172.       mov      si,OFFSET string    ; Load address and length of string
  173.           mov     cl,2
  174.       rep      movsb
  175.       mov      WORD PTR es:[di],0    ; Put double null at end
  176.       sub      ax,ax            ; Return 0 for success
  177.       ret
  178.  
  179. noroom:      inc      ax            ; Return nonzero for fail
  180.       ret
  181. DoEnviron ENDP
  182.  
  183. ; Procedure GetEnv
  184. ; Purpose   Find and measure the environment
  185. ; Input        None
  186. ; Output    Segment of environment in ES, size in AX, length in    CX
  187.  
  188. GetEnv      PROC
  189.       mov      dx,es:10h        ; Load segment of COMMAND.COM
  190.       mov      es,dx            ;   into ES
  191.       mov      ax,es:2Ch        ; Load COMMAND.COM's environment
  192.       or      ax,ax            ; Is it    0?
  193.       jnz      secondry        ; No? This is a    secondary command
  194.                     ;   and    we have    its environment    in AX
  195.       dec      dx            ; Yes? This is original    COMMAND.COM
  196.       mov      es,dx            ;   so point ES    to paragraph before PSP
  197.       add      dx,es:03        ; Offset of environment    is 3 bytes in
  198.       add      dx,2            ; Adjust it back to PSP
  199.       mov      ax,dx            ; Put it in AX
  200.  
  201. secondry: mov     si,ax                 ; Save a copy
  202.       sub      dx,dx            ; Clear    DX for multiply
  203.       dec      ax            ; Get paragaraph before    environment
  204.       mov      es,ax            ; Load into DS
  205.       mov      ax,es:03        ; Size in paragraphs is    at byte    4
  206.       mov      cx,16            ; Multiply by 16
  207.       mul      cx
  208.       mov      es,si            ; Restore environment address
  209.       sub      di,di            ; Point    to start
  210.       mov      cx,ax            ; Load maximum count (size of
  211.       mov      bx,ax            ;   environment) and save a copy
  212.       sub      ax,ax            ; Search for double null
  213. null2:      repne      scasb            ; Look for null
  214.       jz      noerr            ; If not out of    space, continue
  215.       sub      ax,ax            ;   else error (return 0)
  216.       jmp      error2
  217. noerr:      cmp      BYTE PTR es:[di],0    ; Is it    double null?
  218.       jne      null2            ; No? Look again
  219.       mov      cx,di            ; Yes? Save length in CX
  220.       mov      ax,bx            ; Reload size to AX
  221.  
  222.       ret
  223. GetEnv      ENDP
  224. CODE      ENDS
  225.           END     BEG                   ; End assembly
  226.  
  227.