palli011000
asked on
How to read REG_RESOURCE_LIST in Delphi
I need to read this value from registry
HKEY_LOCAL_MACHINE\HARDWAR E\RESOURCE MAP\System Resources\Physical Memory + (.Translated)
Any help appreciated.
Palli
HKEY_LOCAL_MACHINE\HARDWAR
Any help appreciated.
Palli
hi,
just wondering if you know about the GlobalMemoryStatus() api ?
maybe you could use it instead,for instance to show total physical memory you can do:
procedure TForm1.Button1Click(Sender : TObject);
var
PMemStat: ^TMemoryStatus;
begin
New(PMemStat);
GlobalMemoryStatus(PMemSta t^);
label1.caption :=
Format('Physical Memory Available to Windows: %10.0n KB', [pMemstat.dwTotalPhys / 1024]);
Dispose(PMemStat);
end;
the tmemory structure has
dwLength; // sizeof(MEMORYSTATUS)
dwMemoryLoad; // percent of memory in use
dwTotalPhys; // bytes of physical memory
dwAvailPhys; // free physical memory bytes
dwTotalPageFile; // bytes of paging file
dwAvailPageFile; // free bytes of paging file
dwTotalVirtual; // user bytes of address space
dwAvailVirtual; // free user bytes
just wondering if you know about the GlobalMemoryStatus() api ?
maybe you could use it instead,for instance to show total physical memory you can do:
procedure TForm1.Button1Click(Sender
var
PMemStat: ^TMemoryStatus;
begin
New(PMemStat);
GlobalMemoryStatus(PMemSta
label1.caption :=
Format('Physical Memory Available to Windows: %10.0n KB', [pMemstat.dwTotalPhys / 1024]);
Dispose(PMemStat);
end;
the tmemory structure has
dwLength; // sizeof(MEMORYSTATUS)
dwMemoryLoad; // percent of memory in use
dwTotalPhys; // bytes of physical memory
dwAvailPhys; // free physical memory bytes
dwTotalPageFile; // bytes of paging file
dwAvailPageFile; // free bytes of paging file
dwTotalVirtual; // user bytes of address space
dwAvailVirtual; // free user bytes
Hello
just add memo1 on the form, and the value will show in it
Uses Registry;
procedure TForm1.Button1Click(Sender : TObject);
const
Val : String = '.Translated';
var
Data : Array of Byte;
S : String;
sz : Word;
I : Word;
Reg : TRegistry;
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('\HARDWARE\RES OURCEMAP\S ystem Resources\Physical Memory',false) then
begin
sz := Reg.GetDataSize(Val);
if sz > 0 then
begin
SetLength(Data, sz);
Reg.ReadBinaryData(Val, Data[0], sz);
S := Val + ' = ';
for I := 0 to sz - 1 do
S := S + Format('%2x',[Data[I]]);
Memo1.Text := S;
end;
end;
Reg.Free;
end;
Best regards
Mohammed Nasman
just add memo1 on the form, and the value will show in it
Uses Registry;
procedure TForm1.Button1Click(Sender
const
Val : String = '.Translated';
var
Data : Array of Byte;
S : String;
sz : Word;
I : Word;
Reg : TRegistry;
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('\HARDWARE\RES
begin
sz := Reg.GetDataSize(Val);
if sz > 0 then
begin
SetLength(Data, sz);
Reg.ReadBinaryData(Val, Data[0], sz);
S := Val + ' = ';
for I := 0 to sz - 1 do
S := S + Format('%2x',[Data[I]]);
Memo1.Text := S;
end;
end;
Reg.Free;
end;
Best regards
Mohammed Nasman
ASKER
i need to do this remote inthe, read remote registry
ASKER
question for Mohammed Nasman:
how can i then tranlate this into i.e.. 128.MB
Palli
how can i then tranlate this into i.e.. 128.MB
Palli
ASKER
i think i need some translation here
I have found this in a newsgroup.
Regards Jacco
Arthur,
you'll need Win32::TieRegistry and POSIX modules for this....
$nbName is the machine name of the remote computer w/out any slashes.
$RAM returns the amount of RAM in MB.
#####
use Win32::TieRegistry;
use POSIX;
$Registry->Delimiter("/");
sub PhysRAM {
print "Now checking ram\n";
if ($key = $Registry->Connect
($nbName,"LMachine/Hardwar e/Resource Map/System
Resources/Physical Memory/")) {
$RAM = ceil ((unpack "L*", $key->GetValue('.Translate d'))[-1] /
1024
/ 1024 + 16);
print "Done\n";
}
}
Regards Jacco
Arthur,
you'll need Win32::TieRegistry and POSIX modules for this....
$nbName is the machine name of the remote computer w/out any slashes.
$RAM returns the amount of RAM in MB.
#####
use Win32::TieRegistry;
use POSIX;
$Registry->Delimiter("/");
sub PhysRAM {
print "Now checking ram\n";
if ($key = $Registry->Connect
($nbName,"LMachine/Hardwar
Resources/Physical Memory/")) {
$RAM = ceil ((unpack "L*", $key->GetValue('.Translate
1024
/ 1024 + 16);
print "Done\n";
}
}
ASKER
i need this for Delphi, sorry
I thought maybe someone knew how to translate this from perl and POSIX to Delphi...
I believe unpack converts the bytes to an array of unsigned longs (4 bytes) and the [-1] selects the last entry.
Ceil round up the number.
Now I am not sure how the bytes of the LongInt are stored... MSB LSB (or 16bit MSB LSB). But I'll test tomorrow.
Regards Jacco
So converted to Delphi (using mnasmans sample):
procedure TForm1.Button1Click(Sender : TObject);
const
Val : String = '.Translated';
var
Data : Array of Byte;
S : String;
sz : Word;
I : Word;
Reg : TRegistry;
RAM: LongInt;
MB: Integer;
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('\HARDWARE\RES OURCEMAP\S ystem Resources\Physical Memory',false) then
begin
sz := Reg.GetDataSize(Val);
if sz > 0 then
begin
SetLength(Data, sz);
Reg.ReadBinaryData(Val, Data[0], sz);
// don't know about MSB LSB though
RAM := 0;
for I := sz-4 to sz-1 do
RAM := (RAM shl 8) + Data[I];
MB := Round(RAM / 1024 / 1024 + 16 + 0.5);
end;
end;
Reg.Free;
end;
Ceil round up the number.
Now I am not sure how the bytes of the LongInt are stored... MSB LSB (or 16bit MSB LSB). But I'll test tomorrow.
Regards Jacco
So converted to Delphi (using mnasmans sample):
procedure TForm1.Button1Click(Sender
const
Val : String = '.Translated';
var
Data : Array of Byte;
S : String;
sz : Word;
I : Word;
Reg : TRegistry;
RAM: LongInt;
MB: Integer;
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('\HARDWARE\RES
begin
sz := Reg.GetDataSize(Val);
if sz > 0 then
begin
SetLength(Data, sz);
Reg.ReadBinaryData(Val, Data[0], sz);
// don't know about MSB LSB though
RAM := 0;
for I := sz-4 to sz-1 do
RAM := (RAM shl 8) + Data[I];
MB := Round(RAM / 1024 / 1024 + 16 + 0.5);
end;
end;
Reg.Free;
end;
ASKER
thanks, i will wait
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hello
if you want to read the Physical memorty in windows nt why u don't use GlobalMemoryStatus?
procedure TForm1.Button1Click(Sender : TObject);
var
MemoryStatus: TMemoryStatus;
begin
MemoryStatus.dwLength := sizeof(MemoryStatus);
GlobalMemoryStatus(MemoryS tatus);
Label1.Caption := 'Total Physical Memory: ' +
FloatToStr(round(MemorySta tus.dwTota lPhys /1024/1024));
end;
if you want to read the Physical memorty in windows nt why u don't use GlobalMemoryStatus?
procedure TForm1.Button1Click(Sender
var
MemoryStatus: TMemoryStatus;
begin
MemoryStatus.dwLength := sizeof(MemoryStatus);
GlobalMemoryStatus(MemoryS
Label1.Caption := 'Total Physical Memory: ' +
FloatToStr(round(MemorySta
end;
ASKER
yes Jacco this works very fine, how did you solve this anyway?
ASKER
Is freeware RXLib ready for D6?
I searched the WEB for a translation of the POSIX & Perl source code which I found at
http://www.mail-archive.com/perl-win32-admin@listserv1.activestate.com/msg00138.html
I only needed translations for:
ceil
unpack
and array index [-1]
Regards Jacco
http://www.mail-archive.com/perl-win32-admin@listserv1.activestate.com/msg00138.html
I only needed translations for:
ceil
unpack
and array index [-1]
Regards Jacco
ASKER
well done, the points is yours.
Palli
Palli
The resource is small so a
Buffer: array [0..4096] of Byte; //or whatever the data is
should be enough to hold the data.