Solved

Problems with reading from registry

Posted on 2001-09-10
8
158 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
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…

860 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