Solved

Problems with reading from registry

Posted on 2001-09-10
8
151 Views
Last Modified: 2010-04-06
Hi there,

I've got a problem with registry, I can't read the values, even though they exist. It's driving m crazy now, so I wonder if you can help me. Here is my code:

procedure TMainForm.GetNICInfo;
var
  Reg         : TRegistry;
  n           : integer;
  ServiceName : string;
  Description : string;
  MyKey       : string;
  Val         : TStringList;
begin
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_LOCAL_MACHINE;
  ComboBox1.Clear;
  Val := TStringList.Create;
  for n := 1 to 3 do
    begin
      MyKey := '\Software\Windows NT\CurrentVersion\NetworkCards\' +
        IntToStr(n);
      if Reg.OpenKey(MyKey, false) then
        begin
          Reg.GetValueNames(Val);
          Memo1.Lines.AddStrings(Val);
          if Reg.ValueExists('ServiceName') then
            ServiceName := Reg.ReadString('ServiceName');
          if Reg.ValueExists('Description') then
            begin
              Description := Reg.ReadString  ('Description');
              ComboBox1.Items.Add('[' + IntToStr(n) + '] ' + Description);
            end;
        end;
    end;
  Reg.Free;
end;

I even tried the sample code for GetValueNames, but it didn't work either.
I'm using D6 on a Win2K and I've got admin rights.

Regards,
Morten
0
Comment
Question by:mdrasted
8 Comments
 
LVL 22

Accepted Solution

by:
mnasman earned 300 total points
ID: 6472293
Hello

  I'm at home and i don't have windows nt right now, but i think you should change this line:

MyKey := '\Software\Windows NT\CurrentVersion\NetworkCards\'
to
MyKey := '\Software\Micrsoft\Windows NT\CurrentVersion\NetworkCards\'

you forgot to include microsoft in the key

0
 
LVL 17

Expert Comment

by:inthe
ID: 6472552
mnasman is right ..
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6473714
you might want to make sure you spell Microsoft right though.

;)

J.
0
 
LVL 22

Expert Comment

by:mnasman
ID: 6473780
oops, I wrote Micrsoft not Microsoft, lol

I Tested this today in win2k, and your code fine, just add microsoft

 MyKey := '\Software\Microsoft\Windows NT\CurrentVersion\NetworkCards\' +
       IntToStr(n);
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Author Comment

by:mdrasted
ID: 6474139
I added Microsoft, and tried again. But the problem persist. I keep getting an empty response.

Regards,
Morten
0
 
LVL 22

Expert Comment

by:mnasman
ID: 6474152
It's test it and that workied fine with me
open the regedit
and look for the key, if you really have it in ur system
0
 
LVL 3

Expert Comment

by:raidos
ID: 6474250
I've made some changes to your code...
I guess your trying to achieve something like this..


procedure TForm1.GetNICInfo;
var
 Reg:TRegistry;
 n:integer;
 ServiceName:string;
 Description:string;
 MyKey:string;
 Val:TStringList;
begin
 Reg := TRegistry.Create;
 Reg.RootKey := HKEY_LOCAL_MACHINE;
 ComboBox1.Clear;
 Val := TStringList.Create;
 MyKey := '\Software\Microsoft\Windows NT\CurrentVersion\NetworkCards\';
 if Reg.OpenKey(MyKey, false) then begin
   Reg.GetKeyNames(Val);
   Memo1.Lines.Clear;
   Memo1.Lines.AddStrings(Val);
   Reg.CloseKey;
   For n := 0 To Memo1.Lines.Count-1 Do Begin
     If Reg.OpenKey(MyKey + Memo1.Lines[n], false) Then Begin
       if Reg.ValueExists('ServiceName') then
         ServiceName := Reg.ReadString('ServiceName');
       if Reg.ValueExists('Description') then begin
         Description := Reg.ReadString('Description');
         ComboBox1.Items.Add('[' + Memo1.Lines[n] + '] ' + Description);
       end;
       Reg.CloseKey;
     End;
   End;
 end;
 Reg.Free;
 Val.Free;
end;


Good luck
//raidos
0
 
LVL 1

Author Comment

by:mdrasted
ID: 6474304
I'm sorry guys! I was starring myself blind on this. I forgot to remove a line of code I used for test. But it's true that 'Microsoft' was missing. I must be too tired to code, so I'll go home and get some sleep. Thanks for your help :-)

Regards,
Morten
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now