Option Explicit Dim blnQuiet, intArgs, objRE, strURL blnQuiet = False intArgs = 0 strURL = "" Set objRE = New RegExp objRE.Pattern = "^[fehilpst]{3,5}://" objRE.IgnoreCase = False With WScript.Arguments If .Unnamed.Count = 1 Then strURL = .Unnamed(0) If objRE.Test( strURL ) Then intArgs = intArgs + 1 End If End If If .Named.Exists("Q") Then blnQuiet = True intArgs = intArgs + 1 End If If intArgs <> .Count Then Syntax If strURL = "" Then Syntax End With Lookup strURL Sub Lookup( myURL ) Dim objHTTP, strResult Const WinHttpRequestOption_UserAgentString = 0 Const WinHttpRequestOption_URL = 1 Const WinHttpRequestOption_URLCodePage = 2 Const WinHttpRequestOption_EscapePercentInURL = 3 Const WinHTTPRequestError_Timeout = &H80072EE2 On Error Resume Next Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" ) objHTTP.Open "GET", myURL, False objHTTP.SetTimeouts 100, 100, 100, 100 objHTTP.Send objHTTP.WaitForResponse 100 ' Ignore timeouts, as we induce them by setting very "impatient" timeout values If Err.Number <> 0 And Err.Number <> WinHTTPRequestError_Timeout Then WScript.Echo "Error 0x" & Hex( Err.Number ) & vbTab & Err.Description Else strResult = objHTTP.Option( WinHttpRequestOption_URL ) If strResult = myURL Then If blnQuiet Then WScript.Echo strResult Else WScript.Echo "Target URL : " & strResult End If Else If Not blnQuiet Then WScript.Echo "Redirected : " & myURL Lookup strResult End If End If Set objHTTP = Nothing On Error Goto 0 End Sub Sub Syntax Dim strMsg strMsg = vbCrLf _ & "LookupURL.vbs, Version 1.00" _ & vbCrLf _ & "Display the destination URL for a redirected URL" _ & vbCrLf & vbCrLf _ & "Usage: CSCRIPT.EXE // NoLogo LOOKUPURL.VBS url [ /Q ]" _ & vbCrLf & vbCrLf _ & "Where: url is the redirected URL to be investigated" _ & vbCrLf _ & " /Q displays the destination URL only" _ & vbCrLf & vbCrLf _ & "Example: LOOKUPURL.VBS http://robvanderwoude.com/wshexamples_l.html"_ & vbCrLf _ & "Returns: Redirected : http://robvanderwoude.com/wshexamples_l.html" _ & vbCrLf _ & " Target URL : http://www.robvanderwoude.com/wshexamples.php?fc=l" _ & vbCrLf & vbCrLf _ & "Written by Rob van der Woude" _ & vbCrLf _ & "http://www.robvanderwoude.com" WScript.Echo strMsg WScript.Quit 1 End Sub