急救,如何用程序彻底删除IE历史记录?重点要删除History下的记录 ( 积分: 50 )

  • 主题发起人 主题发起人 xbbtzhao
  • 开始时间 开始时间
X

xbbtzhao

Unregistered / Unconfirmed
GUEST, unregistred user!
急救,如何用程序彻底删除IE历史记录?重点要删除History下的记录
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,Registry,wininet,FileCtrl,shlobj,shellapi;

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

var
Form1: TForm1;

implementation

{$R *.DFM}
procedure DelRegCache;
var
reg:TRegistry;
begin
reg:=Tregistry.create;
reg.RootKey:=HKEY_CURRENT_USER;
reg.DeleteKey('Software/Microsoft/Internet Explorer/TypedURLs');
reg.Free;
end;

function GetCookiesFolder:string;
var
pidl:pItemIDList;
buffer:array [ 0..255 ] of char ;
begin
SHGetSpecialFolderLocation(
application.Handle , CSIDL_COOKIES, pidl);

SHGetPathFromIDList(pidl, buffer);
result:=strpas(buffer);
end;

function ShellDeleteFile(sFileName: string): Boolean;
var
FOS: TSHFileOpStruct;
begin
FillChar(FOS, SizeOf(FOS), 0); {记录清零}
with FOS do
begin
wFunc := FO_DELETE;//删除
pFrom := PChar(sFileName);
fFlags := FOF_NOCONFIRMATION;
end;
Result := (SHFileOperation(FOS) = 0);
end;

procedure DelCookie;
var
dir:string;
begin
InternetSetOption(nil, INTERNET_OPTION_END_BROWSER_SESSION, nil, 0);
dir:=GetCookiesFolder;
ShellDeleteFile(dir+'/*.txt');
end;

procedure DelHistory;
var
lpEntryInfo: PInternetCacheEntryInfo;
hCacheDir: LongWord ;
dwEntrySize, dwLastError: LongWord;
begin
dwEntrySize := 0;
FindFirstUrlCacheEntry(nil, TInternetCacheEntryInfo(nil^), dwEntrySize);
GetMem(lpEntryInfo, dwEntrySize);

hCacheDir := FindFirstUrlCacheEntry(nil, lpEntryInfo^, dwEntrySize);
if hCacheDir <> 0 then
DeleteUrlCacheEntry(lpEntryInfo^.lpszSourceUrlName);
FreeMem(lpEntryInfo);

repeat
dwEntrySize := 0;
FindNextUrlCacheEntry(hCacheDir, TInternetCacheEntryInfo(nil^),
dwEntrySize);
dwLastError := GetLastError();
if dwLastError = ERROR_INSUFFICIENT_BUFFER then //如果成功
begin
GetMem(lpEntryInfo, dwEntrySize); {分配dwEntrySize字节的内存}
if FindNextUrlCacheEntry(hCacheDir, lpEntryInfo^, dwEntrySize) then
DeleteUrlCacheEntry(lpEntryInfo^.lpszSourceUrlName);
FreeMem(lpEntryInfo);
end;
until (dwLastError = ERROR_NO_MORE_ITEMS);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
try
screen.cursor:=crHourGlass;
DelRegCache;
DelCookie;
DelHistory;
finally
screen.cursor:=crDefault;
end;
end;

end.
 
winexec(pchar('cmd /c del c:/aaa/*.* /q'),sw_hide);

我这是删除c:/aaa文件夹下的全部文件,你改改路径,应该可以。
 
fsldg:的方法,procedure DelHistory;没有效果,其它OK
下面的方法:有时候可行,有时候又清出不了History
type
TSTATURL = record
cbSize: DWORD;
pwcsUrl: DWORD;
pwcsTitle: DWORD;
ftLastVisited: FILETIME;
ftLastUpdated: FILETIME;
ftExpires: FILETIME;
dwFlags: DWORD;
end;

type
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;

type
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: TSTATURL): HResult; stdcall;
function BindToObject(pocsUrl: PWideChar; var riid: TGUID; out ppvOut: Pointer): HResult; stdcall;
function EnumUrls(out ppenum: IEnumSTATURL): HResult; stdcall;
end;

type
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;

function ClearIEHistory:integer;
const
CLSID_CUrlHistory: TGUID = '{3C374A40-BAE4-11CF-BF7D-00AA006946EE}';
var
IEHistory:IUrlHistoryStg2;
begin
IEHistory:=CreateComObject(CLSID_CUrlHistory) as IUrlHistoryStg2;
IEHistory.ClearHistory;
end;
 
多人接受答案了。
 
后退
顶部