WEB LISTING 2: Which.vbs BEGIN COMMENT ' VBScript file to tell you where in your path the first and subsequent ' instances of an executable are. ' Created by GFC 2002.02.20. END COMMENT On Error Resume Next set objCmdArgs = WScript.Arguments If objCmdArgs.Count < 1 Then Usage() End If intStart = 0 If LCase(objCmdArgs(0)) = "-a" Then If objCmdArgs(1) = "" Then Usage() End If strAll = "Yes" intStart = 1 End If ExtCheck(objCmdArgs(intStart)) set objShell = WScript.CreateObject("WScript.Shell") set objFS = WScript.CreateObject("Scripting.FileSystemObject") strPath = objShell.ExpandEnvironmentStrings("%PATH%") strPath = strPATH & “:.” strEXT = objShell.ExpandEnvironmentStrings("%PATHEXT%") arrEXT = Split(strEXT,";") arrPATH = Split(strPATH,";") strFound = "No" For a = 0 to UBound(arrPATH) For b = 0 to UBound(arrEXT) strFile = arrPATH(a) & "\" & objCmdArgs(intStart) & arrEXT(b) If objFS.FileExists(strFile) Then WScript.Echo LCase(objCmdArgs(intStart)) & UCase(arrEXT(b)) & " is in: " & arrPATH(a) strFound = "Yes" If strAll = "" Then WScript.Quit 0 End If End If Next Next If strFound = "No" Then WScript.Echo "<" & objCmdArgs(intStart) & "> is not anywhere in the PATH." End If set objCmdArgs = Nothing set objShell = Nothing set objFS = Nothing WScript.Quit 0 Function ExtCheck(strArg) set objRegExp = New RegExp BEGIN COMMENT ' I've never seen an executable with numbers in the extension, but if so... ' objRegExp.Pattern = "\.[a-z,0-9]{3}$" END COMMENT objRegExp.Pattern = "\.[a-z]{3}$" objRegExp.IgnoreCase = True set collEXTMatch = objRegExp.Execute(strArg) If collEXTMatch.Count <> 0 Then Usage() End If set collEXTMatch = Nothing set objRegExp = Nothing End Function Function Usage() WScript.Echo vbCrLf & "Usage: which [-a] command-to-find" & vbCrLf & vbCrLf & "Note:" & vbCrLf & "Do *not* enter any EXTension" WScript.Quit 1 End Function