Tuesday, January 20, 2009

Enumerating URLs in Internet Explorer

Enumerating URLs in Internet Explorer

 

# PowerShell

$shell = new-object –com Shell.Application

$windows = $shell.Windows()

write-output ($windows.count.ToString() + " windows found")
foreach ($window in $windows) {
  if ($window.FullName -like "*iexplore*") {
    write-output ($window.LocationURL + ", " + $window.LocationName)
  }
}

$shell = $null



' VBScript
' Find the URLs of the currently running Internext Explorer Windows

' References:
http://windowssdk.msdn.microsoft.com/en-us/library/ms630310.aspx
http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/objects/internetexplorer.asp

Const IE_EXE = "iexplore.exe"

Call FindCurrentURLs(strURLSet)
WScript.Echo strURLSet

wscript.quit(0)

Function FindCurrentURLs(ByRef strURLSet)
Dim objShell, objWindowSet, objWindow
Dim strwindowName, strURL, strFullName

Set objShell = CreateObject("Shell.Application")    ' Create a Windows shell automation object
Set objWindowSet = objShell.Windows      ' Get the collection of open windows belonging to the shell

Wscript.Echo "Processing " & objWindowSet.Count & " windows"   ' Report how many instances were found

For Each objWindow in objWindowSet      ' For each InternetExplorer object in the ShellWindows set
  strFullName = objWindow.FullName     ' Get the full path and executable of this window
  If InStr(1, strFullName, IE_EXE, 1) <> 0 Then    ' Is this an IE shell object?
   strURL = objWindow.LocationURL     ' Get the URL

   If strURL <> "" Then
    strURLSet = strURLSet & vbCRLF & strURL   ' Append to the set of URLs
   End If
  Else         ' No, probably explorer.exe skip
   WScript.Echo "Skipped " & strFullName & " - not IE"
  End If
Next

If Len(strURLSet) >= Len(vbCRLF) Then strURLSet = Right(strURLSet, Len(strURLSet) - Len(vbCRLF)) ' Strip the leading vbCRLF

Set objShell = Nothing
Set objWindowSet = Nothing : Set objWindow = Nothing
End Function


-------------------
Thanks,
http://sccm07.blogspot.com/

No comments: