Solved

Problems with reading from registry

Posted on 2001-09-10
8
159 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:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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