scripting@wanadoo.nl




MapDrv()

http://www.scriptlogic.com/kixtart/FunctionLibrary_FunctionList.aspx


actual FunctionLibrary list on 'Scriptlogic' site printer-friendly mirror of UDF topic on 'scripting@wanadoo.nl' site close
9 January 2002 MapDrv()
AuthorW.M. Hinsch (New Mexico Mark)
Action Briefly describe the action of the function.
SyntaxMapDrv ("Drive_Letter", "Server", "Share") 
Parameters
  • Drive_Letter (Required / String) The drive letter to map (trailing ":" is optional)
  • Server (Required / String) The server where the share is located (leading "\\" is optional)
  • Share (Required / String) The share on \\server 
  • RemarksThe return code is an integer that may be evaluated with bitwise operations. 
    ReturnsAn integer code (only five bits used)

    0 Already mapped correctly

    Or a summation of the following codes

    1 Deleted old mapping
    2 Mapped drive
    4 Share not found
    8 Unable to delete previous drive mapping
    16 Unable to map drive 
    DependenciesNone. 
    Examples
     GOSUB map_drvs
    :ex_prog
     SLEEP 30
     EXIT
    :map_drvs
     $server = "\\@wksta"
     $letter = "X:"
     $share = "C$"
     $map = MapDrv($letter,$server,$share)
     GOSUB eval_map
     $share = "NOTASHARE"
     $map = MapDrv($letter,$server,$share)
     GOSUB eval_map
     $share = "Admin$"
     $map = MapDrv($letter,$server,$share)
     GOSUB eval_map
     RETURN
    :eval_map
     ; These messages may be written without reference to specific information and
     ; sum the function calls as follows:
     ; $Map = $Map | MapDrv("X:","\\SERVER","Share")
     "Map = " + $map ?
     IF $map = 0   "Drive " + $letter + " already mapped correctly." ?             ENDIF
     IF $map & 1   "Deleted drive mapping to " + $letter + "." ?                   ENDIF
     IF $map & 2   "Mapped " + $letter + " drive to " + $share + "." ?             ENDIF
     IF $map & 4   "Share " + $share + " not found." ?                             ENDIF
     IF $map & 8   "Unable to delete " + $letter + " drive mapping." ?             ENDIF
     IF $map & 16  "Unable to map " + $letter + " to " + $server + "\" + $share ?  ENDIF
     RETURN
    
     
    Source
    FUNCTION MapDrv ($lttr, $srvr, $shre)
      ; Returns
      ;  0 = Already mapped correctly
      ; Or returns a summation of one or more of the following event codes
      ;  1 = Deleted old mapping
      ;  2 = Mapped drive
      ;  4 = Share not found
      ;  8 = Unable to delete previous drive mapping
      ; 16 = Unable to map drive
      ;
      $lttr = "" + Ucase(Substr($lttr,1,1))
      $srvr = "" + $srvr
      $shre = "" + $shre
      DIM $strregsubkey, $strregentry, $strregval, $strnewmap
      IF Substr($srvr,1,2) <> "\\" $srvr = "\\" + $srvr ENDIF
      $strregsubkey = "HKEY_CURRENT_USER\network\" + $lttr
      $strregentry  = "RemotePath"
      $strnewmap    = $srvr + "\" + $shre
      $mapdrv = 0                                         ; Clear error flags
      IF KeyExist($strregsubkey)                          ; Drive is mapped
        $strregval = ReadValue($strregsubkey,$strregentry)
        IF ($strregval <> $strnewmap)                     ; Mapped incorrectly
        ELSE                                              ; Not mapped correctly
          IF Exist($strnewmap)                            ; Share exists
            USE "$Lttr:" /delete /persistent              ; Delete current mapping
            IF KeyExist($strregsubkey)                    ; Not deleted
              $mapdrv = $mapdrv | 8                       ; Flag "unable to delete"
            ELSE                                          ; Log deleted drive
              $mapdrv = $mapdrv | 1                       ; Flag "deleted old mapping"
              USE "$Lttr:" "$strNewMap" /persistent       ; Map drive
              IF ReadValue($strregsubkey,$strregentry) = $strnewmap ; Mapped correctly now
                "You are here 2" ?
                $mapdrv = $mapdrv | 2                     ; Flag "mapped drive"
              ELSE                                        ; Still not mapped correctly
                $mapdrv = $mapdrv | 16                    ; Flag "unable to map" error
              ENDIF
            ENDIF
          ELSE                                            ; Share does not exist
            $mapdrv = $mapdrv | 4                         ; Flag "share not found" error
          ENDIF
        ENDIF
      ELSE                                                ; Drive not mapped. Map it.
        USE "$Lttr:" "$Srvr\$Shre" /persistent            ; Map drive
        IF ReadValue($strregsubkey,$strregentry) = $strnewmap ; Mapped correctly
          $mapdrv = $mapdrv | 2                           ; Flag "drive mapped" error
        ELSE
          $mapdrv = $mapdrv | 16                          ; Flag "unable to map" error
        ENDIF
      ENDIF
    ENDFUNCTION ; - MapDrv -
     
      original source of UDF topic. show actual FunctionLibrary list on Scriptlogic site close top
              printer-friendly mirror of UDF topic on scripting@wanadoo.nl site  




    Copyright © 2003 www.scriptlogic.com & scripting@wanadoo.nl - last updated on 20 May 2003


    Site Meter