Solved

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

Posted on 2006-07-14
5
207 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now