Option Explicit Function Subst() Const sDivider = "\: => " Dim oShell, oExec, i, sLine, iLineLength, iDividerPosition, sDrive, sPath, aDrives() Set oShell = WScript.CreateObject("WScript.Shell") Set oExec = oShell.Exec("subst.exe") i = 0 Do While Not oExec.StdOut.AtEndOfStream sLine = oExec.StdOut.ReadLine() iLineLength = Len(sLine) iDividerPosition = InStr(sLine, sDivider) sDrive = Left(sLine, iDividerPosition - 1) sPath = Right(sLine, iLineLength - iDividerPosition - 5) ReDim Preserve aDrives(1, i) aDrives(0, i) = sDrive aDrives(1, i) = sPath i = i + 1 Loop Subst = aDrives End Function Function ExpandSubstDrive(ByRef sDrive) Dim i, aDrives ExpandSubstDrive = sDrive aDrives = Subst() For i = 0 To UBound(aDrives, 2) If not (aDrives(0, i) <> sDrive) Then ExpandSubstDrive = aDrives(1, i) Exit For End If Next End Function MsgBox ExpandSubstDrive("X:") |