?
Solved

How to read REG_RESOURCE_LIST in Delphi

Posted on 2001-09-04
18
Medium Priority
?
1,188 Views
Last Modified: 2012-05-04
I need to read this value from registry

HKEY_LOCAL_MACHINE\HARDWARE\RESOURCEMAP\System Resources\Physical Memory + (.Translated)

Any help appreciated.
Palli
0
Comment
Question by:palli011000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 2
  • +2
18 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6452800
A TRegistry's ReadBinaryData should do the trick.
The resource is small so a
Buffer: array [0..4096] of Byte; //or whatever the data is
should be enough to hold the data.
0
 
LVL 17

Expert Comment

by:inthe
ID: 6452802
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(PMemStat^);
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
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6452845
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\RESOURCEMAP\System 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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:Jacco
ID: 6452852
Here is something I found:

http://www.streichernet.de/nttips/nttip991225-1.htm

Regards Jacco
0
 

Author Comment

by:palli011000
ID: 6453381
i need to do this remote inthe, read remote registry
0
 

Author Comment

by:palli011000
ID: 6453389
question for Mohammed Nasman:
how can i then tranlate this into i.e.. 128.MB

Palli
0
 

Author Comment

by:palli011000
ID: 6453698
i think i need some translation here
0
 
LVL 10

Expert Comment

by:Jacco
ID: 6454115
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/Hardware/ResourceMap/System
Resources/Physical Memory/")) {

     $RAM = ceil ((unpack "L*", $key->GetValue('.Translated'))[-1] /
1024
/ 1024 + 16);
print "Done\n";


}


}

0
 

Author Comment

by:palli011000
ID: 6454146
i need this for Delphi, sorry
0
 
LVL 10

Expert Comment

by:Jacco
ID: 6454597
I thought maybe someone knew how to translate this from perl and POSIX to Delphi...
0
 
LVL 10

Expert Comment

by:Jacco
ID: 6454709
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\RESOURCEMAP\System 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;



0
 

Author Comment

by:palli011000
ID: 6455171
thanks, i will wait
0
 
LVL 10

Accepted Solution

by:
Jacco earned 1000 total points
ID: 6456811
Hi Palli,

I tested this and it works.

Regards Jacco

procedure TForm1.Button1Click(Sender: TObject);
const
  Val  : String = '.Translated';
var
  Data : Array of Byte;
  S    : String;
  sz   : Word;
  I,Cnt: Word;
  Reg : TRegistry;
  RAM: Int64;
  MB: Integer;
const
  SHFT: array[0..3] of Integer = (0, 8, 16, 24);
begin
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_LOCAL_MACHINE;
  if Reg.OpenKey('\HARDWARE\RESOURCEMAP\System Resources\Physical Memory',false) then
  begin
    sz := Reg.GetDataSize(Val);
    if sz > 0 then
      begin
        SetLength(Data, sz);
        Reg.ReadBinaryData(Val, Data[0], sz);
        RAM := 0;
        Cnt := 0;
        for I := sz-4 to sz-1 do
        begin
          RAM := RAM + Data[I] shl SHFT[Cnt];
          Inc(Cnt);
        end;
        MB := Round(RAM / 1024 / 1024 + 16 + 0.5);
        ShowMessage(IntToStr(MB)+' MB');
      end;
  end;
  Reg.Free;
end;
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6456840
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(MemoryStatus);
  Label1.Caption := 'Total Physical Memory: ' +
    FloatToStr(round(MemoryStatus.dwTotalPhys /1024/1024));
end;
0
 

Author Comment

by:palli011000
ID: 6457581
yes Jacco this works very fine, how did you solve this anyway?
0
 

Author Comment

by:palli011000
ID: 6457695
Is freeware RXLib ready for D6?
0
 
LVL 10

Expert Comment

by:Jacco
ID: 6457814
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
0
 

Author Comment

by:palli011000
ID: 6457861
well done, the points is yours.
Palli
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question