Solved

Problems with reading from registry

Posted on 2001-09-10
8
164 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
[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 Comments
 
LVL 22

Accepted Solution

by:
Mohammed Nasman 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
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 22

Expert Comment

by:Mohammed Nasman
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
 
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:Mohammed Nasman
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

Industry Leaders: 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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

705 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