1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
unit Assoc1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Registry,
StdCtrls ;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure ListBox1DblClick(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
// récupéré dans shlwapi.pas
const
// ASSOCF enumerated values mapped to integer constants
ASSOCF_INIT_NOREMAPCLSID = $00000001;
ASSOCF_INIT_BYEXENAME = $00000002;
ASSOCF_OPEN_BYEXENAME = $00000002;
ASSOCF_INIT_DEFAULTTOSTAR = $00000004;
ASSOCF_INIT_DEFAULTTOFOLDER = $00000008;
ASSOCF_NOUSERSETTINGS = $00000010;
ASSOCF_NOTRUNCATE = $00000020;
ASSOCF_VERIFY = $00000040;
ASSOCF_REMAPRUNDLL = $00000080;
ASSOCF_NOFIXUPS = $00000100;
ASSOCF_IGNOREBASECLASS = $00000200;
{$MINENUMSIZE 4}
type
TAssocStr = (ASSOCSTR_NONE,
ASSOCSTR_COMMAND,
ASSOCSTR_EXECUTABLE,
ASSOCSTR_FRIENDLYDOCNAME,
ASSOCSTR_FRIENDLYAPPNAME,
ASSOCSTR_NOOPEN,
ASSOCSTR_SHELLNEWVALUE,
ASSOCSTR_DDECOMMAND,
ASSOCSTR_DDEIFEXEC,
ASSOCSTR_DDEAPPLICATION,
ASSOCSTR_DDETOPIC );
// uniquement utile pour lisibilité résultat
const
AssocStrDisplaystrings : array [ASSOCSTR_COMMAND..ASSOCSTR_DDETOPIC]
of string = (
'ASSOCSTR_COMMAND',
'ASSOCSTR_EXECUTABLE',
'ASSOCSTR_FRIENDLYDOCNAME',
'ASSOCSTR_FRIENDLYAPPNAME',
'ASSOCSTR_NOOPEN',
'ASSOCSTR_SHELLNEWVALUE',
'ASSOCSTR_DDECOMMAND',
'ASSOCSTR_DDEIFEXEC',
'ASSOCSTR_DDEAPPLICATION',
'ASSOCSTR_DDETOPIC' );
function AssocQueryString( Flags: Integer; StrType: TAssocStr;
pszAssoc, pszExtra: PChar; pszOut:
PChar; Var pcchPut: DWORD): HRESULT; stdcall;
external 'shlwapi.dll' name 'AssocQueryStringA';
// lecture valeur registre REG_MULTI_SZ
procedure ReadREG_MULTI_SZ(const CurrentKey: HKey; const Subkey, ValueName: string;
Strings: TStrings);
var
valueType: DWORD;
valueLen: DWORD;
p, buffer: PChar;
key: HKEY;
begin
// Clear TStrings
Strings.Clear;
// open the specified key
if RegOpenKeyEx(CurrentKey,
PChar(Subkey),
0, KEY_READ, key) = ERROR_SUCCESS then
begin
// retrieve the type and data for a specified value name
SetLastError(RegQueryValueEx(key,
PChar(ValueName),
nil,
@valueType,
nil,
@valueLen));
if GetLastError = ERROR_SUCCESS then
if valueType = REG_MULTI_SZ then
begin
GetMem(buffer, valueLen);
try
// receive the value's data (in an array).
RegQueryValueEx(key,
PChar(ValueName),
nil,
nil,
PBYTE(buffer),
@valueLen);
// Add values to stringlist
p := buffer;
while p^ <> #0 do
begin
Strings.Add(p);
Inc(p, lstrlen(p) + 1)
end
finally
FreeMem(buffer)
end
end
else
raise ERegistryException.Create('Stringlist attendue')
else
raise ERegistryException.Create('Impossible de lire la valeur MULTI_SZ');
end;
end;
// remplissage de la liste , nouveaux possibles selon poste
procedure TForm1.Button1Click(Sender: TObject);
begin
ReadREG_MULTI_SZ(HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Explorer\Discardable\PostSetup\ShellNew','Classes', ListBox1.Items);
end;
// affichage des commandes selon choix
procedure TForm1.ListBox1DblClick(Sender: TObject);
var i : Word;
Bufsize : DWORD;
buffer : array [0..1024] of Char;
begin
BufSize := Sizeof(Buffer);
Buffer[0] := #0;
for i:=0 to listbox1.Items.Count-1 do
begin
if Listbox1.Selected[i] then
begin
memo1.lines.Clear;
AssocQueryString(ASSOCF_NOTRUNCATE,ASSOCSTR_EXECUTABLE,Pchar(listbox1.Items[i]),'open',Buffer,BufSize );
memo1.lines.Add(Format('Value for %s: %s',[AssocStrDisplaystrings[ASSOCSTR_EXECUTABLE], Buffer]));
BufSize := Sizeof(Buffer);
Buffer[0] := #0;
AssocQueryString(ASSOCF_NOTRUNCATE,ASSOCSTR_COMMAND,Pchar(listbox1.Items[i]),'new',Buffer,BufSize );
memo1.lines.Add(Format('Value A for %s: %s',[AssocStrDisplaystrings[ASSOCSTR_COMMAND], Buffer]));
BufSize := Sizeof(Buffer);
Buffer[0] := #0;
AssocQueryString(ASSOCF_NOTRUNCATE,ASSOCSTR_FRIENDLYDOCNAME,Pchar(listbox1.Items[i]),'',Buffer,BufSize );
memo1.lines.Add(Format('Value for %s: %s',[AssocStrDisplaystrings[ASSOCSTR_FRIENDLYDOCNAME], Buffer]));
BufSize := Sizeof(Buffer);
Buffer[0] := #0;
AssocQueryString(ASSOCF_NOTRUNCATE,ASSOCSTR_FRIENDLYAPPNAME,Pchar(listbox1.Items[i]),'',Buffer,BufSize );
memo1.lines.Add(Format('Value for %s: %s',[AssocStrDisplaystrings[ASSOCSTR_FRIENDLYAPPNAME], Buffer]));
BufSize := Sizeof(Buffer);
Buffer[0] := #0;
AssocQueryString(ASSOCF_NOTRUNCATE,ASSOCSTR_NOOPEN,Pchar(listbox1.Items[i]),'',Buffer,BufSize);
memo1.lines.Add(Format('Value for %s: %s',[AssocStrDisplaystrings[ASSOCSTR_NOOPEN], Buffer]));
BufSize := Sizeof(Buffer);
Buffer[0] := #0;
AssocQueryString(ASSOCF_NOTRUNCATE,ASSOCSTR_SHELLNEWVALUE,Pchar(listbox1.Items[i]),'new',Buffer,BufSize);
memo1.lines.Add(Format('Value for %s: %s',[AssocStrDisplaystrings[ASSOCSTR_SHELLNEWVALUE], Buffer]));
end;
end;
end;
end. |
Partager