Unit PageFile.pas
unit PageFile;
interface
{unit PageFile.pas}
uses
Windows, Messages, SysUtils, Variants, Classes, ComCtrls, StdCtrls,
Registry, types, Dialogs;
function litcle(chemin :string; valeur: String; endroit : integer;typevaleur:integer):string;
procedure ecritcle(chemin :string; cle: string; valeur: String; endroit : integer;typevaleur:integer);
procedure supprimevaleur(chemin :string;cle: string;endroit :integer);
type DWORD = Longword;
implementation
function litcle(chemin :string; valeur: String; endroit : integer;typevaleur:integer):string;
var registrelit: TRegistry;
positionreg : integer;
valeurhex :longword;
begin
registrelit:=TRegistry.Create;
positionreg:=endroit;
if positionreg=0 then
begin
registrelit.RootKey:=HKEY_LOCAL_MACHINE;
end;
if positionreg=1 then
begin
registrelit.RootKey:=HKEY_CLASSES_ROOT;
end;
if positionreg=2 then
begin
registrelit.RootKey:=HKEY_CURRENT_USER;
end;
if positionreg=3 then
begin
registrelit.RootKey:=HKEY_LOCAL_MACHINE;
end;
if positionreg=4 then
begin
registrelit.RootKey:=HKEY_USERS;
end;
if positionreg=5 then
begin
registrelit.RootKey:=HKEY_CURRENT_CONFIG;
end;
registrelit.OpenKey(chemin,false);
if typevaleur=0 then
begin
if registrelit.ValueExists(valeur) then
begin
result:=registrelit.ReadString(valeur);
end
else
begin
result:='';
end;
end;
if typevaleur=1 then
begin
if registrelit.ValueExists(valeur) then
begin
valeurhex:=registrelit.readinteger(valeur);
result:=inttostr(valeurhex);
end
else
begin
result:='';
end;
end;
registrelit.CloseKey;
registrelit.Free;
end;
procedure ecritcle(chemin :string; cle:string; valeur: String; endroit : integer;typevaleur:integer);
var registreecrit: TRegistry;
positionreg : integer;
chaine :string;
valeurhex :integer;
begin
registreecrit:=TRegistry.Create;
positionreg:=endroit;
chaine:=valeur;
if positionreg=0 then
begin
registreecrit.RootKey:=HKEY_LOCAL_MACHINE;
end;
if positionreg=1 then
begin
registreecrit.RootKey:=HKEY_CLASSES_ROOT;
end;
if positionreg=2 then
begin
registreecrit.RootKey:=HKEY_CURRENT_USER;
end;
if positionreg=3 then
begin
registreecrit.RootKey:=HKEY_LOCAL_MACHINE;
end;
if positionreg=4 then
begin
registreecrit.RootKey:=HKEY_USERS;
end;
if positionreg=5 then
begin
registreecrit.RootKey:=HKEY_CURRENT_CONFIG;
end;
registreecrit.OpenKey(chemin,true);
if typevaleur=0 then
begin
registreecrit.WriteString(cle,chaine);
registreecrit.CloseKey;
end;
if typevaleur=1 then
begin
valeurhex:=strtoint64(valeur);
registreecrit.WriteInteger(cle,valeurhex);
registreecrit.CloseKey;
end;
registreecrit.Free;
end;
procedure supprimevaleur(chemin: string;cle: string;endroit :integer);
var registresupprime: TRegistry;
positionreg : integer;
begin
registresupprime:=Tregistry.Create;
positionreg:=endroit;
if positionreg=0 then
begin
registresupprime.RootKey:=HKEY_LOCAL_MACHINE;
end;
if positionreg=1 then
begin
registresupprime.RootKey:=HKEY_CLASSES_ROOT;
end;
if positionreg=2 then
begin
registresupprime.RootKey:=HKEY_CURRENT_USER;
end;
if positionreg=3 then
begin
registresupprime.RootKey:=HKEY_LOCAL_MACHINE;
end;
if positionreg=4 then
begin
registresupprime.RootKey:=HKEY_USERS;
end;
if positionreg=5 then
begin
registresupprime.RootKey:=HKEY_CURRENT_CONFIG;
end;
registresupprime.OpenKey(chemin,false);
registresupprime.DeleteValue(cle);
registresupprime.CloseKey;
registresupprime.Free;
end;
end.
uses PageFile, ShellAPI
type
st200=string[200];
function Executefichier(const fichier, params,
Directory : st200;showcmd: integer):Thandle;
var
ZFile, Zparams,Zdir:array [0..200] of char;
begin
result:= ShellExecute(Application.mainForm.Handle,nil,
strPcopy(zFile,fichier),strPcopy(zParams,Params),
StrPCopy(zdir, Directory),showcmd);
end;
//
procedure TForm1.FormCreate(Sender: TObject);
var
see : string;
begin
see := litcle('SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management',
'ClearPageFileAtShutdown',0,1);
if see = '1' then
begin
RadioButton1.Checked:=true;
end;
if see = '0' then
begin
RadioButton2.Checked:=true;
end;
end;
Beispiel :
procedure TForm1.Button1Click(Sender: TObject);
begin
if Radiobutton1.Checked then
begin
ecritcle('SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management',
'ClearPageFileAtShutdown','1',0,1);
showmessage('the PageFile will be purged at the Next Shutdown! (longer shutdown)');
end;
if Radiobutton2.Checked then
begin
ecritcle('SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management',
'ClearPageFileAtShutdown','0',0,1);
showmessage('the PageFile will not purge for a quick shutdown');
end;
executefichier('shutdown.exe','-r -t 00', 'C:\WINDOWS\system32\',SW_HIDE);
Application.Terminate;
end;
Keine Kommentare:
Kommentar veröffentlichen