카테고리 없음

[윈도우즈 API] "임시 인터넷 파일" 전부 지우기

쇼핑스크래퍼2 2023. 9. 4. 08:09

ㅊㅊㅊㅊㅊ

unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation
{$R *.dfm}

procedure DeleteIECache;
var
  lpEntryInfo: PInternetCacheEntryInfo;
  hCacheDir: LongWord;
  dwEntrySize: LongWord;
begin
  dwEntrySize := 0;
  FindFirstUrlCacheEntry(nil, TInternetCacheEntryInfo(nil^), dwEntrySize);
  GetMem(lpEntryInfo, dwEntrySize);
  if dwEntrySize > 0 then lpEntryInfo^.dwStructSize := dwEntrySize;
  hCacheDir := FindFirstUrlCacheEntry(nil, lpEntryInfo^, dwEntrySize);
  if hCacheDir <> 0 then  
  begin
    repeat
     //delete all
      DeleteUrlCacheEntry(lpEntryInfo^.lpszSourceUrlName);

{
     // delete cookies
      if ((lpEntryInfo^.CacheEntryType and COOKIE_CACHE_ENTRY) =
COOKIE_CACHE_ENTRY)
     // delete history
      or ((lpEntryInfo^.CacheEntryType and URLHISTORY_CACHE_ENTRY) =
URLHISTORY_CACHE_ENTRY)
     // delete "normal" cache
      or ((lpEntryInfo^.CacheEntryType and NORMAL_CACHE_ENTRY) =
NORMAL_CACHE_ENTRY)
        then DeleteUrlCacheEntry(lpEntryInfo^.lpszSourceUrlName);
}

      FreeMem(lpEntryInfo, dwEntrySize);
      dwEntrySize := 0;
      FindNextUrlCacheEntry(hCacheDir, TInternetCacheEntryInfo(nil^), dwEntrySize);
      GetMem(lpEntryInfo, dwEntrySize);
      if dwEntrySize > 0 then lpEntryInfo^.dwStructSize := dwEntrySize;
    until not FindNextUrlCacheEntry(hCacheDir, lpEntryInfo^, dwEntrySize);
  end;
  FreeMem(lpEntryInfo, dwEntrySize);
  FindCloseUrlCache(hCacheDir);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  TheReg: TRegistry;
  KeyName: String;
  ValueStr: String;
begin
  ValueStr := '';

  TheReg := TRegistry.Create;
  try
     TheReg.RootKey := HKEY_CURRENT_USER;
     KeyName := 'SoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders';
     if TheReg.OpenKey(KeyName, False) then
     begin
        ValueStr := TheReg.ReadString('Cache');
        TheReg.CloseKey;
     end;
  finally
     TheReg.Free;
  end;

  if MessageDlg('폴더 ('+ValueStr+') 의 파일들을 전부 삭제하시겠습니다 ?',
                mtConfirmation,[mbYes,mbNo],0) = mrYes then
    DeleteIECache
end;

end.