Author Topic: Help With Drive Mapping  (Read 2738 times)

0 Members and 1 Guest are viewing this topic.

deegeecees

  • Guest
Help With Drive Mapping
« on: December 08, 2005, 05:26:18 PM »
Ok Lisp Jockeys, need some help on this one. I have some code from Mr. Menzi that lists network paths and remaps network paths. I haven't coded in a while, so ANY help would be extremely appreciated as I am pressed for time (new user coming in tomorrow, and I'm thinking this way is faster than me spending hours on the trial/error method). I'm puting together an app that will check drive mapping and change it accordingly. Here's the parameters:

Jurg Menzi's Code:


Code: [Select]
VxListNetworkDrives - Returns a list of all mapped network drives with UNC...
 
 
;
; -- Function VxListNetworkDrives
; Returns a list of all mapped network drives with UNC path.
; Copyright:
;   ©2005 MENZI ENGINEERING GmbH, Switzerland
; Arguments [Typ]:
;   --- =
; Return [Typ]:
;   > List of mapped drives '(("X:" . "\\\\Server\\Xpath")...) [LIST]
; Notes:
;   - Requires ScrRun.dll (see also notes at top of page).
;
(defun VxListNetworkDrives ( / DrvCol ItmCnt RetVal WsnObj)
 (setq WsnObj (vlax-create-object "WScript.Network")
       DrvCol (vlax-invoke WsnObj 'EnumNetworkDrives)
       ItmCnt 0
 )
 (repeat (/ (vlax-invoke DrvCol 'Count) 2)
  (setq RetVal (cons
                (cons
                 (strcase (vla-Item DrvCol ItmCnt))
                 (vla-Item DrvCol (1+ ItmCnt))
                )
                RetVal
               )
        ItmCnt (+ ItmCnt 2)
  )
 )
 (vlax-release-object WsnObj)
 (reverse RetVal)
)
 
Back  
 
VxRemapNetworkDrives - Remaps a network drive to another drive letter
 
 
;
; -- Function VxRemapNetworkDrive
; Remaps a network drive to another drive letter.
; Copyright:
;   ©2005 MENZI ENGINEERING GmbH, Switzerland
; Arguments [Typ]:
;   Old = Old drive letter, eg. "X:" [STR]
;   New = New drive letter, eg. "Y:" [STR]
; Return [Typ]:
;   > True: Remapping sucessfull
;   > False: Remapping failed
; Notes:
;   - Requires ScrRun.dll (see also notes at top of page).
;
(defun VxRemapNetworkDrive (Old New / OldUnc RetVal WsnObj)
 (setq WsnObj (vlax-create-object "WScript.Network")
       OldUnc (cdr (assoc (strcase Old) (VxListNetworkDrives)))
 )
 (cond
  ((vl-catch-all-apply
    'vlax-invoke
    (list WsnObj 'RemoveNetworkDrive Old :vlax-true :vlax-true)
   )
  )
  ((vl-catch-all-apply
    'vlax-invoke
    (list WsnObj 'MapNetworkDrive New OldUnc :vlax-true)
   )
  )
  ((setq RetVal T))
 )
 (vlax-release-object WsnObj)
 RetVal
)

Resulting dotted pairs from function to list mapping:
Quote
Command: (VxListNetworkDrives)
(("E:" . "\\\\springfield2\\cad") ("G:" . "\\\\lisledc2\\cad") ("H:" .
"\\\\lisledc1\\word") ("I:" . "\\\\lisledc1\\engr") ("J:" .
"\\\\application1\\applications") ("K:" . "\\\\lisledc1\\projects") ("N:" .
"\\\\lisledc2\\tranprojects") ("O:" . "\\\\lisledc2\\office") ("R:" .
"\\\\lisledc2\\communications") ("T:" . "\\\\lisledc1\\temp") ("Y:" .
"\\\\nas2\\archive") ("Z:" . "\\\\lisledc2\\projectscomed") ("X:" .
"\\\\lisledc2\\archive") ("P:" . "\\\\lisledc1\\projects") ("Q:" .
"\\\\lisledc2\\projectscomed") ("S:" . "\\\\lisledc2\\programs"))

I'm only concerned with these two:
Quote
("P:" . "\\\\lisledc1\\projects")
("Q:" . "\\\\lisledc2\\projectscomed")

Iterate through the list looking for correct UNC, then grab the CAR and reset it.

Clear as mud?

I'm gonna attempt my HACK mode at this, and see if I can get an answer for myself before anyone else.

The race is ON!

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Help With Drive Mapping
« Reply #1 on: December 08, 2005, 05:42:24 PM »
Does it have to be lisp?

net Use P: /Del /YES
net Use Q: /Del /YES
net use P: \\lisledc1\projects /YES
net use Q: \\lisledc2\projectscomed /YES

This in a bat file will map the drives.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

deegeecees

  • Guest
Re: Help With Drive Mapping
« Reply #2 on: December 08, 2005, 05:53:06 PM »
Yes, ronjonp that works. Sorry to cut it short, gotta go.