![]() |
Arbeiten mit der Registry ohne TRegistry
Delphi-Quellcode:
Christian Seehase
function WriteStringToRegAPI(const p_sSubKey : string;const p_sValueName : string;const p_sValue : string) : integer;
var hResult : HKEY; begin // Es ginge auch RegOpenKeyEx, so wird ein nicht existenter Key aber angelegt. // Existiert der SubKey, wird er geöffnet Result := RegCreateKeyEx(HKEY_CURRENT_USER,PChar(p_sSubKey),0,nil,0,KEY_ALL_ACCESS,nil,hResult,nil); if Result <> ERROR_SUCCESS then begin exit; end; try Result := RegSetValueEx(hResult,PChar(p_sValueName),0,REG_SZ,@p_sValue[1],Length(p_sValue)+1); finally RegCloseKey(hResult); end; end; function ReadStringFromRegAPI(const p_sSubKey : string; const p_sValueName : string;var p_sResult : string) : integer; var hResult : HKEY; dwMaxValueLen : DWORD; szResult : PChar; begin Result := RegOpenKeyEx(HKEY_CURRENT_USER,PChar(p_sSubKey),0,KEY_ALL_ACCESS,hResult); if Result <> ERROR_SUCCESS then begin exit; end; try Result := RegQueryInfoKey(hResult,nil,nil,nil,nil,nil,nil,nil,nil,@dwMaxValueLen,nil,nil); if Result <> ERROR_SUCCESS then begin exit; end; inc(dwMaxValueLen); szResult := StrAlloc(dwMaxValueLen); try Result := RegQueryValueEx(hResult,PChar(p_sValueName),nil,nil,PByte(szResult),@dwMaxValueLen); if Result <> ERROR_SUCCESS then begin exit; end; p_sResult := trim(szResult); finally StrDispose(szResult); end; finally RegCloseKey(hResult); end; end; procedure TForm1.Button1Click(Sender: TObject); var iResult : integer; sResult : string; begin iResult := WriteStringToRegAPI('Software\CSE\TEST','TESTWERTNAME','TESTWERT'); if iResult <> ERROR_SUCCESS then begin ShowMessage(SysErrorMessage(iResult)); end; iResult := ReadStringFromRegAPI('Software\CSE\TEST','TESTWERTNAME',sResult); if iResult <> ERROR_SUCCESS then begin ShowMessage(SysErrorMessage(iResult)); end else begin ShowMessage(sResult); end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:01 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz