바이너리로 들어있는 부분을 긁어내오는
테스트된 코드입니다..
즐거운 프로그래밍 하시길~
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Registry;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function FileTimeToDateTime(FileTime: TFileTime): TDateTime;
var
SystemTime: TSystemTime;
begin
FileTimeToLocalFileTime(FileTime, FileTime);
FileTimeToSystemTime(FileTime, SystemTime);
Result := SystemTimeToDateTime(SystemTime);
end;
function GetCacheInfo(ThisRegSection: string): string;
type
TSlowInfoCache = record
cbSize: DWORD;
HasName: LongBool;
InstallSize: Int64;
LastUsed: TFileTime;
Frequency: Integer;
Name: array[0..261] of WideChar;
end;
var
MyInfoCache: TSlowInfoCache;
TmpBytArray: array[0..551] of byte;
s1: string;
ThisReg: TRegistry;
begin
// returns a quote encapsulated csv string, as follows;
// '"Status","InstallSize","DateTime-of-LastUse","Frequency-of-Use","Name"';
s1 := '"Invalid","","","",""';
ThisReg := TRegistry.Create;
try
ThisReg.RootKey := HKEY_CURRENT_USER;
//ThisReg.RootKey:=HKEY_LOCAL_MACHINE;
ThisReg.Access := Key_Read;
if ThisReg.OpenKey(ThisRegSection, False) then
begin
ThisReg.ReadBinaryData('SlowInfoCache', TmpBytArray, SizeOf(TmpBytArray));
MyInfoCache := TSlowInfoCache(TmpBytArray);
if MyInfoCache.HasName then
begin
s1 := '"Valid","';
s1 := s1 + IntToStr(MyInfoCache.InstallSize) + '","';
s1 := s1 +
DateTimeToStr(FileTimeToDateTime(MyInfoCache.LastUsed)) + '","';
//s1 := s1 + IntToStr(Int64((MyInfoCache.LastUsed.dwHighDateTime shl 32) +
// MyInfoCache.LastUsed.dwLowDateTime)) + '","';
s1 := s1 + IntToStr(MyInfoCache.Frequency) + '","';
s1 := s1 + string(MyInfoCache.Name) + '"';
end;
ThisReg.CloseKey;
end;
finally
if Assigned(ThisReg) then
ThisReg.Free;
end;
result := s1;
end;
procedure Traverse_ARP_list(TheseStrings: TStrings = nil);
var
MyReg: TRegistry;
MyList: TStrings;
i1: Integer;
BaseKey: string;
ThisCacheInfo: string;
begin
BaseKey :=
'SOFTWARE\Microsoft\Windows\CurrentVersion\App Management\ARPCache\';
MyReg := TRegistry.Create;
MyList := TStringList.Create;
try
MyReg.RootKey := HKEY_CURRENT_USER;
MyReg.Access := KEY_READ;
if MyReg.OpenKey(BaseKey, false) then
MyReg.GetKeyNames(MyList);
MyReg.CloseKey;
for i1 := 0 to pred(MyList.Count) do
begin
ThisCacheInfo := GetCacheInfo(BaseKey + MyList.Strings[i1]);
if pos('"Valid"', ThisCacheInfo) <> 0 then
begin // data is good
if TheseStrings <> nil then
TheseStrings.Add(ThisCacheInfo);
end
else
begin // data is NOT useful
end;
end;
finally
if Assigned(MyReg) then
MyReg.Free;
if Assigned(MyList) then
MyList.Free;
end;
end;
//설치프로그램 목록이다
procedure TForm1.Button1Click(Sender: TObject);
const
CLAVE =
'\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall';
var
reg: TRegistry;
Lista: TStringList;
Lista2: TStringList;
i, n: integer;
begin
ListBox1.Clear;
reg := TRegistry.Create;
Lista := TStringList.Create;
Lista2 := TStringList.Create;
with Reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
OpenKey(CLAVE, false);
GetKeyNames(Lista);
end;
for i := 0 to Lista.Count - 1 do
begin
reg.OpenKey(CLAVE + '\' + Lista.Strings[i], false);
reg.GetValueNames(Lista2);
n := Lista2.IndexOf('DisplayName');
if (n <> -1) and (Lista2.IndexOf('UninstallString') <> -1) then
begin
//ListBox1.Items.Add(reg.ReadString(Lista2.Strings[n]));
ListBox1.Items.Add(reg.ReadString(Lista2.Strings[n]) + '-' +
reg.ReadString(Lista2.Strings[Lista2.IndexOf('UninstallString')]));
end;
end;
Lista.Free;
Lista2.Free;
reg.CloseKey;
reg.Destroy;
end;
//설치된 프로그램 목록중에서 사용빈도, 마지막 실행된 날짜등을 구한다
procedure TForm1.Button2Click(Sender: TObject);
begin
ListBox1.Clear;
Traverse_ARP_list(ListBox1.Items);
end;
end.