Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problems with reading from registry

Posted on 2001-09-10
8
Medium Priority
?
172 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 1200 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
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!

 
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

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

610 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