function SetPrivilege(Privilege: PChar; EnablePrivilege: Boolean;
out PreviousState: Boolean): DWORD;
var
Token: THandle;
NewState: TTokenPrivileges;
Luid: TLargeInteger;
PrevState: TTokenPrivileges;
Return: DWORD;
begin
PreviousState := True;
if (GetVersion() > $80000000) then
// Win9x
Result := ERROR_SUCCESS
else
begin
// WinNT
if not OpenProcessToken(GetCurrentProcess(), MAXIMUM_ALLOWED, Token) then
Result := GetLastError()
else
try
if not LookupPrivilegeValue(nil, Privilege, Luid) then
Result := GetLastError()
else
begin
NewState.PrivilegeCount := 1;
NewState.Privileges[0].Luid := Luid;
if EnablePrivilege then
NewState.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
else
NewState.Privileges[0].Attributes := 0;
if not AdjustTokenPrivileges(Token, False, NewState,
SizeOf(TTokenPrivileges), PrevState, Return) then
Result := GetLastError()
else
begin
Result := ERROR_SUCCESS;
PreviousState :=
(PrevState.Privileges[0].Attributes and SE_PRIVILEGE_ENABLED <> 0);
end;
end;
finally
CloseHandle(Token);
end;
end;
end;
function RegSaveKeyToFile(Key: HKEY; const SubKey, FileName: string): DWORD;
const
SE_BACKUP_NAME = 'SeBackupPrivilege';
var
PreviousState: Boolean;
KeyHandle: HKEY;
begin
Result := SetPrivilege(SE_BACKUP_NAME, True, PreviousState);
if (Result = ERROR_SUCCESS) then
try
KeyHandle := 0;
Result := RegOpenKeyEx(Key, PChar(SubKey), 0, MAXIMUM_ALLOWED, KeyHandle);
if (Result = ERROR_SUCCESS) then
try
// FIXME: Short Filename on Win9x!
Result := RegSaveKey(KeyHandle, PChar(FileName), nil);
finally
RegCloseKey(KeyHandle);
end;
finally
if (not PreviousState) then
SetPrivilege(SE_BACKUP_NAME, PreviousState, PreviousState);
end;
end;
function RegLoadKeyFromFile(Key: HKEY; const SubKey, Filename: string): DWORD;
const
SE_BACKUP_NAME = 'SeBackupPrivilege';
SE_RESTORE_NAME = 'SeRestorePrivilege';
var
PrevBackup: Boolean;
PrevRestore: Boolean;
KeyHandle: HKEY;
ShortName: array [0..MAX_PATH] of Char;
begin
Result := SetPrivilege(SE_BACKUP_NAME, True, PrevBackup);
if (Result = ERROR_SUCCESS) then
try
Result := SetPrivilege(SE_RESTORE_NAME, True, PrevRestore);
if (Result = ERROR_SUCCESS) then
try
if (GetVersion() > $80000000) then
begin // (FIXME: Test it! - and see RegReplaceKey)
if (GetShortPathName(PChar(Filename), ShortName, MAX_PATH) = 0) then
Result := GetLastError()
else
Result := RegLoadKey(Key, PChar(SubKey), ShortName);
end
else
begin // (FIXME: Load RegRestoreKey dynamically!)
KeyHandle := 0;
Result := RegOpenKeyEx(Key, PChar(SubKey), 0, MAXIMUM_ALLOWED, KeyHandle);
if (Result = ERROR_SUCCESS) then
try
Result := RegRestoreKey(KeyHandle, PChar(Filename), 0);
finally
RegCloseKey(KeyHandle);
end;
end;
finally
if (not PrevRestore) then
SetPrivilege(SE_RESTORE_NAME, PrevRestore, PrevRestore);
end;
finally
if (not PrevBackup) then
SetPrivilege(SE_BACKUP_NAME, PrevBackup, PrevBackup);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
const
Key = HKEY(HKEY_LOCAL_MACHINE);
SubKey = 'SOFTWARE\Borland\Locales';
var
Filename: string;
ErrorCode: DWORD;
begin
SetLength(Filename, MAX_PATH + 1);
SetLength(Filename, GetTempPath(MAX_PATH, PChar(Filename)));
Filename := Filename + 'Locales.dat';
ErrorCode := RegSaveKeyToFile(Key, SubKey, Filename);
if (ErrorCode <> ERROR_SUCCESS) then
ShowMessage('Save: ' + SysErrorMessage(ErrorCode))
else
begin
ErrorCode := RegLoadKeyFromFile(Key, SubKey, Filename);
if (ErrorCode <> ERROR_SUCCESS) then
ShowMessage('Load: ' + SysErrorMessage(ErrorCode))
else
ShowMessage(IntToStr(42));
end;
//DeleteFile(Filename);
end;

Save & Write Registry Key
Abonnieren
Posts (Atom)
Beliebte Posts
-
Windows Key Sniffer 0.82 - Update 08/2024 Der Windows Key Sniffer hat mir im Laufe der Zeit viel Arbeit erspart und unterstützt, viele Wi...
-
Network Source Code Update Source Code Network Update : https://asciigen.blogspot.com/p/network.html Send Message 1.0 Source Server Client ...
-
Windows Defender Bypass Version 0.75 - Update 11/2024 Den Windows 10-eigenen Virenschutz Defender kann man auf mehreren Wegen abschalt...
-
ASCii GIF Animator Update Version 0.68 (32 bit) - 11/2024 Bei dieser überarbeiteten Version ist die Kompatibilität zu den verschiedenen...
-
MD5 Hacker v.0.26 - Update 08.2024 MD5 Hashs sollten eigentlich nicht entschlüsselt werden können. Jedoch gibt es Tools, mit welchen auch ...
-
Host Editor Version 0.65 - Update 01/2025 Hosts File Editor allows for the easy editing of host files and backup creation. Create your ...
-
Dir Sniffer Version 0.11 - Update 02/2025 Dir Sniffer ist ein kleines aber nützliches Tool um herauszufinden, was ihr Programm auf ihrem...
-
Oldskool Font Generator v.0.29 - Update 11/2023 Das Tool stell 508 Bitmap Fonts zu Verfügung. Eigene Fonts können integriert werden, sie...
-
Hard Crypter 0.19 - Update 12/2023 Mit diesem Tool können Sie jede beliebige Datei auf dem Windows-System verschlüsseln. Die Byte-Erse...
Keine Kommentare:
Kommentar veröffentlichen