Board index » delphi » Getting Cookies from All Running IE Instances

Getting Cookies from All Running IE Instances


2007-05-08 12:14:37 PM
delphi9
I need to be able to iterate though all instances of IE and examine the
underlying OleObject.Document.Cookie to determine if a web site has
authorized so I don't try to log in again, but instead use the existing
credentials in the cookie.
I saw some code that might help, but I do not know how ot get to the
cookies:
var
x : Integer;
ShellWindows : IShellWindows;
Browser : IWebBrowser2;
IE: TInternetExplorer;
begin
Result := '';
{ IShellWindows can provide interfaces to open browser windows. }
ShellWindows := CoShellWindows.Create;
for x := 0 to Pred(ShellWindows.Get_Count) do
ShowMessage( ( ShellWindows.Item( x ) as IWebBrowser2 ).LocationURL );
Browser := ( ShellWindows.Item( 0 ) as IWebBrowser2 );
Any help would be appreciated. Thanks!
-Johnnie
 
 

Re:Getting Cookies from All Running IE Instances

I found a solution to this. I do some extra tests in my real application
code, but this is the technique I used (for future web searchers).
-Johnnie
function FindCookies: string;
var
ShellWindow: IShellWindows;
WB: IWebbrowser2;
spDisp: IDispatch;
iDoc: IHTMLDocument2;
i: Integer;
begin
Result := '';
ShellWindow := CoShellWindows.Create;
for i := 0 to ShellWindow.Count do
begin
spDisp := ShellWindow.Item(i);
if spDisp = nil then Continue;
spDisp.QueryInterface(iWebBrowser2, WB);
if WB <>nil then
begin
WB.Document.QueryInterface(IHTMLDocument2, iDoc);
Result := iDoc.cookie;
end;
end;
end;