Author: Jonas Bilinkevicius
How to read a registry entry of type REG_MULTI_SZ
Answer:
REG_MULTI_SZ is a registry type holding multiple strings. This function reads the
value into a TStrings object and returns true if successful.
1
2 function ReadREG_MULTI_SZ(const HK: HKey; const k, v: string; ts: TStrings):
3 boolean;
4 var
5 vType: DWORD;
6 vLen: DWORD;
7 p, buffer: PChar;
8 key: HKEY;
9 begin
10 result := false;
11 ts.Clear;
12 if (RegOpenKeyEx(HK, PChar(k), 0, KEY_READ, key) = ERROR_SUCCESS) then
13 begin
14 SetLastError(RegQueryValueEx(key, PChar(v), nil, @vType, nil, @vLen));
15 if (GetLastError = ERROR_SUCCESS) and (vType = REG_MULTI_SZ) then
16 begin
17 GetMem(buffer, vLen);
18 try
19 RegQueryValueEx(key, PChar(v), nil, nil, PBYTE(buffer), @vLen);
20 p := buffer;
21 while (p^ <> #0) do
22 begin
23 ts.Add(p);
24 Inc(p, lstrlen(p) + 1)
25 end;
26 finally
27 FreeMem(buffer)
28 end;
29 result := true;
30 end;
31 end;
32 end;
33
34 //Example to read the 'Pagingfiles' value into a TMemo:
35
36 procedure TForm1.Button1Click(Sender: TObject);
37 var
38 k, val: string;
39 begin
40 k := 'SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management';
41 val := 'Pagingfiles';
42 ReadREG_MULTI_SZ(HKEY_LOCAL_MACHINE, k, val, Memo1.Lines);
43 end;
|