Solved

Delete all Temporary Internet Files

Posted on 2000-05-02
9
369 Views
Last Modified: 2010-04-04
How to delete all Temporary Internet Files and all history urls
0
Comment
Question by:cookey
  • 4
  • 3
  • 2
9 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 20 total points
ID: 2769812
0
 

Expert Comment

by:QuazzeMan
ID: 2769814
To delete all Temporary internet files
just delete everything in \windows\temporary internet files\

To clear the history urls you have
to clear some area in the registory
but i dont know where, ill check into it.

Later / Tommy
0
 

Expert Comment

by:QuazzeMan
ID: 2769824
Guess i dont have to.
inthe just knows it all ;-D
0
 

Author Comment

by:cookey
ID: 2770169
Yes, I find the way in http://www.euromind.com/iedelphi/IECache.htm
, but, It must install a component, i want to know a simple way to delete files, I think delete everything in \windows\temporary internet files\ is a good idea, but, it seems not delete completly
0
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.

 
LVL 17

Expert Comment

by:inthe
ID: 2770256
i can give some code for it but its alot of code and is different depending on what version of windows the program is running on.

need to check what version is running
then read a string from registry(read path to temp internet files dir from reg)
then delete all files using findfirst etc in loop..

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,Registry;

type
TForm1 = class(TForm)
Button1: TButton;
ComboBox1: TComboBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

function FindTemporaryFiles : String;
var
TheReg : TRegistry;
TempString : String;
begin
TheReg := TRegistry.Create;
try
TheReg.RootKey := HKEY_LOCAL_MACHINE;
If TheReg.OpenKey('Software\Microsoft\Internet Explorer\Main\', False ) then
begin
TempString := TheReg.ReadString('Cache_Directory');
If Copy(TempString, Length(TempString) - 1, 1) <> '\' then
TempString := TempString + '\';
Result := TempString;
end
else
Result := 'NOTHING';
finally
TheReg.Free;
end;
end;

procedure GatherFiles(Const Lines: TStrings; Const Dir,Match: String);
var
Rec: TSearchRec;
Found: Integer;
Begin
// Add files
Found:= FindFirst(Dir+'\'+Match, faAnyFile, Rec);
While Found = 0 do
begin
If (Rec.Attr AND faDirectory) = 0 Then Lines.Add(Dir+'\'+Rec.Name);
Found := FindNext(Rec);
End;
FindClose(Rec);
// Find directories (Without match)
Found:= FindFirst(Dir+'\*.*', faAnyFile, Rec);
While Found = 0 do
begin
If ((Rec.Attr AND faDirectory)>0) AND (Rec.Name<>'.') AND (Rec.Name<>'..') Then
GatherFiles(Lines,Dir+'\'+Rec.Name,Match);
Found := FindNext(Rec);
End;
FindClose(Rec);
End;

procedure TForm1.Button1Click(Sender: TObject);
Var
TempPath : String;
TheList : TStringList;
i : integer;
begin
TheList := TStringList.Create;
try
TempPath := FindTemporaryFiles;
If (length(TempPath) > 3) AND (UPPERCASE(TempPath) <> 'C:\WINDOWS') AND (UPPERCASE(TempPath) <> 'C:\WINNT') then
begin
GatherFiles(TheList,TempPath,'*.*');
For i := 0 to TheList.Count - 1 do
try
// DeleteFile( TheList[i] );
combobox1.items.add(TheList[i]);
except
end;
End;
finally
TheList.Free;
end;
showmessage('finished');
end;

end.



for win9* pc's the above wil work if you just change the registry path to hkcu \Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\ and read the string "cache" .


here another example maybe works on both (UNTESTED on nt):

unit UrlH_Unit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Activex, Comobj, StdCtrls, ComCtrls, Grids;

const

  STATURL_QUERYFLAG_ISCACHED = $00010000;
  STATURL_QUERYFLAG_NOURL = $00020000;
  STATURL_QUERYFLAG_NOTITLE = $00040000;
  STATURL_QUERYFLAG_TOPLEVEL = $00080000;

  STATURLFLAG_ISCACHED = $00000001;
  STATURLFLAG_ISTOPLEVEL = $00000002;


  IID_IEnumStatUrl: TGUID = (D1: $3C374A42; D2: $BAE4; D3: $11CF; D4: ($BF, $7D, $00, $AA, $00, $69, $46, $EE));
  IID_IUrlHistoryStg: TGUID = (D1: $3C374A41; D2: $BAE4; D3: $11CF; D4: ($BF, $7D, $00, $AA, $00, $69, $46, $EE));
  IID_IUrlHistoryStg2: TGUID = (D1: $AFA0DC11; D2: $C313; D3: $831A; D4: ($83, $1A, $00, $C0, $4F, $D5, $AE, $38));
  IID_IUrlHistoryNotify: TGUID = (D1: $BC40BEC1; D2: $C493; D3: $11D0; D4: ($83, $1B, $00, $C0, $4F, $D5, $AE, $38));

  SID_IEnumStatUrl = '{3C374A42-BAE4-11CF-BF7D-00AA006946EE}';
  SID_IUrlHistoryStg = '{3C374A41-BAE4-11CF-BF7D-00AA006946EE}';
  SID_IUrlHistoryStg2 = '{AFA0DC11-C313-11d0-831A-00C04FD5AE38}';
  SID_IURLHistoryNotify = '{BC40BEC1-C493-11d0-831B-00C04FD5AE38}';
  CLSID_CUrlHistory: TGUID = '{3C374A40-BAE4-11CF-BF7D-00AA006946EE}';


type
  STATURL = record
    cbSize: DWORD;
    pwcsUrl: DWORD;
    pwcsTitle: DWORD;
    ftLastVisited: FILETIME;
    ftLastUpdated: FILETIME;
    ftExpires: FILETIME;
    dwFlags: DWORD;
  end;


  IEnumSTATURL = interface(IUnknown)
    ['{3C374A42-BAE4-11CF-BF7D-00AA006946EE}']
    function Next(celt: Integer; out elt; pceltFetched: PLongint): HRESULT; stdcall;
    function Skip(celt: Longint): HRESULT; stdcall;
    function Reset: HResult; stdcall;
    function Clone(out ppenum: IEnumSTATURL): HResult; stdcall;
    function SetFilter(poszFilter: PWideChar; dwFlags: DWORD): HResult; stdcall;
  end;

  IUrlHistoryStg = interface(IUnknown)
    ['{3C374A41-BAE4-11CF-BF7D-00AA006946EE}']
    function AddUrl(pocsUrl: PWideChar; pocsTitle: PWideChar; dwFlags: Integer): HResult; stdcall;
    function DeleteUrl(pocsUrl: PWideChar; dwFlags: Integer): HResult; stdcall;
    function QueryUrl(pocsUrl: PWideChar; dwFlags: Integer; var lpSTATURL: STATURL): HResult; stdcall;
    function BindToObject(pocsUrl: PWideChar; var riid: TIID; out ppvOut: Pointer): HResult; stdcall;
    function EnumUrls(out ppenum: IEnumSTATURL): HResult; stdcall;
  end;

  IUrlHistoryStg2 = interface(IUrlHistoryStg)
    ['{AFA0DC11-C313-11D0-831A-00C04FD5AE38}']
    function AddUrlAndNotify(pocsUrl: PWideChar; pocsTitle: PWideChar; dwFlags: Integer;
      fWriteHistory: Integer; var poctNotify: Pointer;
      const punkISFolder: IUnknown): HResult; stdcall;
    function ClearHistory: HResult; stdcall;
  end;

  IUrlHistoryNotify = interface(IOleCommandTarget)
    ['{BC40BEC1-C493-11d0-831B-00C04FD5AE38}']
  end;



  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    RetrieveBtn: TButton;
    ClearBtn: TButton;
    procedure RetrieveBtnClick(Sender: TObject);
    procedure ClearBtnClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  I: IUrlHistoryStg2;

implementation

{$R *.DFM}


function FileTimeToDt(Ft: TFileTime): TDateTime;
var
  l: Integer;
  lft: TFileTime;
begin
  FileTimeToLocalFiletime(Ft, lft);
  if FileTimeToDosDateTime(lft, Longrec(l).Hi, Longrec(l).Lo) then
    result := FiledateToDatetime(l) else
    result := 0;
end;


procedure TForm1.RetrieveBtnClick(Sender: TObject);
var
  r: Staturl;
  Enum: IEnumStatUrl;
  X: Integer;
  Row: Integer;
begin
  StringGrid1.Cells[0, 0] := 'Last Visited';
  StringGrid1.Cells[1, 0] := 'Title';
  StringGrid1.Cells[2, 0] := 'Url';
  StringGrid1.Cells[3, 0] := 'Last Updated';
  StringGrid1.Cells[4, 0] := 'Expires';
  Row := 0;
  I := CreateComObject(ClsId_CUrlHistory) as IUrlHistoryStg2;
  I.EnumUrls(Enum);
  Enum.SetFilter('http://', 0);
  while enum.next(1, r, @X) = S_OK do begin
    Inc(Row);
    StringGrid1.RowCount := Row + 1;
    Stringgrid1.Cells[0, Row] := DateTimeToStr(FileTimeToDt(r.ftLastVisited));
    Stringgrid1.Cells[1, Row] := PWidechar(Pointer(r.pwcsTitle));
    Stringgrid1.Cells[2, Row] := PWidechar(Pointer(r.pwcsUrl));
    Stringgrid1.Cells[3, Row] := DateTimeToStr(FileTimeToDt(r.ftLastUpdated));
    Stringgrid1.Cells[4, Row] := DateTimeToStr(FileTimeToDt(r.ftExpires));
  end;
end;

procedure TForm1.ClearBtnClick(Sender: TObject);
begin
I.ClearHistory;
end;

end.





form as text:



object Form1: TForm1
  Left = 192
  Top = 107
  Width = 763
  Height = 349
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object StringGrid1: TStringGrid
    Left = 0
    Top = 0
    Width = 755
    Height = 257
    Align = alTop
    DefaultRowHeight = 14
    FixedCols = 0
    TabOrder = 0
    ColWidths = (
      103
      205
      207
      113
      150)
  end
  object RetrieveBtn: TButton
    Left = 208
    Top = 282
    Width = 137
    Height = 25
    Caption = 'Enumerate UrlHistory'
    TabOrder = 1
    OnClick = RetrieveBtnClick
  end
  object ClearBtn: TButton
    Left = 448
    Top = 282
    Width = 137
    Height = 25
    Caption = 'Clear UrlHistory'
    TabOrder = 2
    OnClick = ClearBtnClick
  end
end

always pays to check what files are really going to be deleted by loading to a combobox first ..
Regards Barry

0
 
LVL 17

Expert Comment

by:inthe
ID: 2770269
the first example posted above is for nt unless the reg key is changed.

i prefer the euromind methods because i consider them "safer" to use.
0
 

Author Comment

by:cookey
ID: 2771874
I tried the second example, It only delete files in "History" directory, can't delete files in "Temporary Internet Files". Must I use 1st example to delete files in "Temporary Internet Files"?
0
 
LVL 17

Expert Comment

by:inthe
ID: 2773920
unit Cacheunit;

interface

uses
  WinInet, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    RetrieveBtn: TButton;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    procedure ListBox1Click(Sender: TObject);
    procedure RetrieveBtnClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


function GetUrlCacheEntryInfo(lpszUrlName: PChar; lpCacheEntryInfo:
  PInternetCacheEntryInfo; var lpdwCacheEntryInfoBufferSize: DWORD): BOOL; stdcall;

function FindFirstUrlCacheEntry(lpszUrlSearchPattern: PChar;
  lpFirstCacheEntryInfo: PInternetCacheEntryInfo;
  var lpdwFirstCacheEntryInfoBufferSize: DWORD): THandle; stdcall;

function FindNextUrlCacheEntry(hEnumHandle: THandle; lpNextCacheEntryInfo:
  PInternetCacheEntryInfo; var lpdwNextCacheEntryInfoBufferSize: DWORD): BOOL; stdcall;


var
  Form1: TForm1;


implementation

{$R *.DFM}


const
  URLHISTORY_CACHE_ENTRY = $00200000;
  winetdll = 'wininet.dll';

function FindFirstUrlCacheEntry; external winetdll name 'FindFirstUrlCacheEntryA';
function FindNextUrlCacheEntry; external winetdll name 'FindNextUrlCacheEntryA';
function GetUrlCacheEntryInfo; external winetdll name 'GetUrlCacheEntryInfoA';



function FileTimeToDt(Ft: TFileTime): string;
var
  l: Integer;
  lft: TFileTime;
begin
  FileTimeToLocalFiletime(Ft, lft);
  if FileTimeToDosDateTime(lft, Longrec(l).Hi, Longrec(l).Lo) then
    result := DateTimeToStr(FiledateToDatetime(l)) else
    result := '';
end;



procedure TForm1.ListBox1Click(Sender: TObject);
var
  T: PInternetCacheEntryInfo;
  D: Cardinal;
begin
  D := 0;
  GetUrlCacheEntryInfo(Pchar(Listbox1.Items[ListBox1.ItemIndex]), T, D); //Get BufferSize
  GetMem(T, D);
  GetUrlCacheEntryInfo(Pchar(Listbox1.Items[ListBox1.ItemIndex]), T, D);
  Label1.Caption := 'Last time accessed: ' + FileTimeToDt(T^.LastAccessTime);
  Label2.Caption := 'Last time syncronized: ' + FileTimeToDt(T^.LastSyncTime);
  Label3.Caption := 'Last time modified: ' + FileTimeToDt(T^.LastModifiedTime);
  Label4.Caption := 'Expires: ' + FileTimeToDt(T^.ExpireTime);
  Label5.Caption := 'Visited: ' + IntToStr(T^.dwHitRate);
  Label6.Caption := 'URL: ' + Copy(T^.lpszSourceUrlName, Pos('@', T^.lpszSourceUrlName) + 1, MAX_PATH);
  FreeMem(T, D);
end;

procedure TForm1.RetrieveBtnClick(Sender: TObject);
var
  T: PInternetCacheEntryInfo;
  D: Cardinal;
  H: THandle;
begin
  D := 0;
  H := FindFirstUrlCacheEntry(nil, nil, D); //Get bufferSize
  GetMem(T, D);
  if D > 0 then T^.dwStructSize := D;
  H := FindFirstUrlCacheEntry(nil, T, D);
  if GetLastError <> 0 then
    repeat
      if (T^.CacheEntryType = T^.CacheEntryType or URLHISTORY_CACHE_ENTRY) then
        Listbox1.Items.Add(T^.lpszSourceUrlName);
      Freemem(T, D);
      D := 0;
      FindNextUrlCacheEntry(H, nil, D); //Get BufferSize
      GetMem(T, D);
      if D > 0 then T^.dwStructSize := D;
    until not FindNextUrlCacheEntry(H, T, D);
  FreeMem(T, D);
  FindCloseUrlCache(H);
  Listbox1.ItemIndex := 0;
  Listbox1Click(sender);
end;

end.

above method should work on all.


you could also use the first method for nt and change reg string of first method to use it also for win9*.
0
 

Author Comment

by:cookey
ID: 2774206
OK, Thank you very much
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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

930 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

13 Experts available now in Live!

Get 1:1 Help Now