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
| program TestReadRegString3;
{ Code extrait de l'unité RegEdit de Paul TOTH :
http://tothpaul.free.fr/sources.php?tools.units
Essai d'adaptation pour Virtual Pascal.
}
{$IFDEF VPASCAL}
{$PMTYPE VIO}
{$H+}
{$ELSE}
{$APPTYPE CONSOLE}
{$ENDIF}
uses
Windows;
var
key: HKEY;
path: string;
value, default: string;
handle: HKEY;
regtype: integer;
datasize: integer;
result: string;
chaine: array[0..511]of char;
{ http://www.developpez.net/forums/d1034628/autres-langages/pascal/lazarus/obtenir-message-d-erreur-d-shellexecute/#post5764683
}
begin
key := HKEY_CURRENT_USER;
//path := 'Software\Embarcadero\BDS\9.0\Closed Projects';
//path := 'Volatile Environment';
path := 'Environment';
//value := 'File_0';
//value := 'USERNAME';
value := 'TMP'; // ou 'TEMP'
default := 'Cha'#140'ne introuvable.';
result := default;
if RegOpenKeyEx(key, pChar(path), 0, KEY_ALL_ACCESS, handle) = ERROR_SUCCESS then
begin
if RegQueryValueEx(handle, pChar(value), nil, @regtype, nil, @datasize) = ERROR_SUCCESS then
begin
SetLength(result, datasize);
RegQueryValueEx(handle, pChar(value), nil, @regtype, PByte(pChar(result)), @datasize);
SetLength(result, datasize - 1);
end else
begin
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nil, GetLastError, 0, @chaine, SizeOf(chaine), nil);
WriteLn('2');
end;
RegCloseKey(handle);
end else
begin
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nil, GetLastError, 0, @chaine, SizeOf(chaine), nil);
WriteLn('1');
end;
WriteLn(result);
if result = default then
begin
CharToOem(chaine, chaine);
WriteLn(chaine);
end;
Write('Appuyez sur la touche Entr'#130'e... ');
ReadLn;
end. |
Partager