Solved

=========> Urgent Urgent Urgent <=========  log visited web site

Posted on 2006-07-14
5
210 Views
Last Modified: 2010-04-05
hi
i want source code for log all visited web site in a Workstation
0
Comment
Question by:mahdiparak
  • 2
5 Comments
 
LVL 2

Expert Comment

by:insomniac92
ID: 17112911
what OS / browser?
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 500 total points
ID: 17113326

This is from an old PAQ I worked on, assuming you are dealing with IE. If so, the code allows you to get all the visited urls, (and cookies, etc) that are currently in the history.

Regards,
Russell

Example usage (form, memo control, and a button)

procedure TForm1.Button1Click(Sender: TObject);
var  dwIndex:       Integer;
begin

  with TUrlCache.Create do
  begin
     GetEntries(utUrl, Memo1.Lines);
     MessageBox(0, 'Click ok to load cookies', nil, MB_OK);
     GetEntries(utCookie, Memo1.Lines);
     MessageBox(0, 'Click ok to load visited sites', nil, MB_OK);
     GetEntries(utVisited, Memo1.Lines);
     MessageBox(0, 'Click ok to load all urls', nil, MB_OK);
     GetEntries(utAll, Memo1.Lines);
     // Clear all urls if OK is clicked
     if (MessageBox(0, 'Click ok to clear cache', nil, MB_OKCANCEL) = ID_OK) then Clear;
     // Free object
     Free;
  end;

end;





Source:

--------------------
unit UrlCache;

interface

uses
  Windows, SysUtils, Classes, WinInet;

const
  DEF_URLSIZE       =  512;  // Average url size. This is used because the structure
                             // for the url entry will always be greater than 80 bytes,
                             // but in general, will be less than 512 bytes. This allows
                             // a balance between allocating too much memory, and having to
                             // perform a realloc on every enumeration call.

type
  TUrlEntryType     =  (utAll, utUrl, utCookie, utVisited);
  TUrlCache         =  class(TObject)
  private
     // Private declarations
     FList:         TList;
     procedure      ClearList;
  protected
     // Protected declarations
     function       GetUrlEntry(Index: Integer): TInternetCacheEntryInfo;
     function       GetCount: Integer;
     procedure      Load;
  public
     // Public declarations
     constructor    Create;
     destructor     Destroy; override;
     procedure      Delete(Index: Integer);
     procedure      Refresh;
     procedure      GetEntries(EntryType: TUrlEntryType; List: TStrings);
     procedure      Clear;
     property       Count: Integer read GetCount;
     property       UrlEntry[Index: Integer]: TInternetCacheEntryInfo read GetUrlEntry; default;
  end;

implementation

procedure TUrlCache.GetEntries(EntryType: TUrlEntryType; List: TStrings);
var  dwIndex:       Integer;
begin

  // Check list
  if Assigned(List) then
  begin
     // Clear list
     List.Clear;
     // Walk all items
     for dwIndex:=0 to Pred(FList.Count) do
     begin
        // Get the specified entry types
        case EntryType of
           // Url sites
           utUrl       :
           begin
              // Not visited: or cookies:
              if (StrLIComp('cookie:', PInternetCacheEntryInfo(FList[dwIndex])^.lpszSourceUrlName, 7) <> 0) and
                 (StrLIComp('visited:', PInternetCacheEntryInfo(FList[dwIndex])^.lpszSourceUrlName, 8) <> 0) then
              begin
                 List.Add(PInternetCacheEntryInfo(FList[dwIndex])^.lpszSourceUrlName);
              end;
           end;
           // Add "cookies:" entries
           utCookie    :
           begin
              if (StrLIComp('cookie:', PInternetCacheEntryInfo(FList[dwIndex])^.lpszSourceUrlName, 7) = 0) then
              begin
                 List.Add(PInternetCacheEntryInfo(FList[dwIndex])^.lpszSourceUrlName);
              end;
           end;
           // Add "visited:" entries
           utVisited   :
           begin
              if (StrLIComp('visited:', PInternetCacheEntryInfo(FList[dwIndex])^.lpszSourceUrlName, 8) = 0) then
              begin
                 List.Add(PInternetCacheEntryInfo(FList[dwIndex])^.lpszSourceUrlName);
              end;
           end;
        else
           // Add the entry
           List.Add(PInternetCacheEntryInfo(FList[dwIndex])^.lpszSourceUrlName);
        end;
     end;
  end;

end;

function TUrlCache.GetCount: Integer;
begin

  // Return entry count
  result:=FList.Count;

end;

procedure TUrlCache.ClearList;
var  dwIndex:       Integer;
begin

  // Free all entries and clear the list
  for dwIndex:=Pred(FList.Count) downto 0 do
  begin
     // Free memory
     FreeMem(FList[dwIndex]);
  end;

  // Clear the list
  FList.Clear;

end;

function TUrlCache.GetUrlEntry(Index: Integer): TInternetCacheEntryInfo;
begin

  // Return the requested entry
  result:=PInternetCacheEntryInfo(FList[Index])^;

end;

procedure TUrlCache.Delete(Index: Integer);
begin

  // Remove from cache
  if DeleteUrlCacheEntry(PInternetCacheEntryInfo(FList[Index]).lpszSourceUrlName) then
  begin
     // Free memory
     FreeMem(FList[Index]);
     // Remove from list
       FList.Delete(Index);
  end;

end;

procedure TUrlCache.Refresh;
begin

  // Just call load
  Load;

end;

procedure TUrlCache.Load;
var  lpCacheEntry:  PInternetCacheEntryInfo;
     hFind:         THandle;
     dwSize:        DWORD;
     bEnum:         Boolean;
begin

  // Allocate memory for the find
  dwSize:=DEF_URLSIZE;
  lpCacheEntry:=AllocMem(dwSize);

  // Find first
  hFind:=FindFirstUrlCacheEntry(nil, lpCacheEntry^, dwSize);
  if (hFind = 0) and (GetLastError = ERROR_INSUFFICIENT_BUFFER) then
  begin
     // Reallocate for required size
     ReAllocMem(lpCacheEntry, dwSize);
     // Perform find again
     hFind:=FindFirstUrlCacheEntry(nil, lpCacheEntry^, dwSize);
  end;

  // Set enum state
  bEnum:=(hFind <> 0);

  // Perform find first/next enumeration
  if bEnum then
  begin
     // Find has started
     while bEnum do
     begin
        // Add entry to list
        FList.Add(lpCacheEntry);
        // Nil the pointer
        lpCacheEntry:=nil;
        // Allocate for find next
        dwSize:=DEF_URLSIZE;
        lpCacheEntry:=AllocMem(dwSize);
        // Find next
        if not(FindNextUrlCacheEntry(hFind, lpCacheEntry^, dwSize)) then
        begin
           // Buffer too small, or no more items?
           if (GetLastError = ERROR_INSUFFICIENT_BUFFER) then
           begin
              // Reallocate for required size
              ReAllocMem(lpCacheEntry, dwSize);
              // Perform find next again
              bEnum:=FindNextUrlCacheEntry(hFind, lpCacheEntry^, dwSize);
           end
           else
              // Done enumeration
              bEnum:=False;
        end
        else
           // Enumerate
           bEnum:=True;
     end;
     // Close the enumeration
     FindCloseUrlCache(hFind);
  end;

  // If entry is assigned then free memory
  if Assigned(lpCacheEntry) then FreeMem(lpCacheEntry);

end;

procedure TUrlCache.Clear;
var  dwIndex:       Integer;
begin

  // This will delete all entries from the cache
  for dwIndex:=Pred(FList.Count) downto 0 do
  begin
     // Remove from cache
     if DeleteUrlCacheEntry(PInternetCacheEntryInfo(FList[dwIndex]).lpszSourceUrlName) then
     begin
        // Free memory
        FreeMem(FList[dwIndex]);
        // Remove from list
        FList.Delete(dwIndex);
     end;
  end;
  if FList.Count > 0 then
     beep;
end;

constructor TUrlCache.Create;
begin

  // Perform inherited
  inherited Create;

  // Create list
  FList:=TList.Create;

  // Load the list
  Load;

end;

destructor TUrlCache.Destroy;
begin

  // Clear all entries from the list
  try
     ClearList;
  finally
     // Free the list
     FList.Free;
  end;

  // Perform inherited
  inherited Destroy;

end;

end.
0
 
LVL 1

Author Comment

by:mahdiparak
ID: 17113783
excellent Rllibby
very thanks
0
 
LVL 1

Author Comment

by:mahdiparak
ID: 17129381
ok
not use again.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question