473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help with registry, array, and listbox

Hello,

In regards to the Registry...

Can someone give me an example of how to list an unknown number of subkeys
under a key, and put the key names in one column of a listbox, and the key
values in another column of a listbox?

Thanks!
Nov 16 '05 #1
3 4278

"vbMark" <no@email.com> wrote in message
news:Xn************************@130.133.1.4...
Hello,

In regards to the Registry...

Can someone give me an example of how to list an unknown number of subkeys
under a key, and put the key names in one column of a listbox, and the key
values in another column of a listbox?

Thanks!


Look at GetSubKeyNames(), and GetValueNames of the RegistryKey object.

HTH,
Eric
Nov 16 '05 #2
"Eric Eggermann" <<none>> wrote in
news:#s**************@TK2MSFTNGP11.phx.gbl:

"vbMark" <no@email.com> wrote in message
news:Xn************************@130.133.1.4...
Hello,

In regards to the Registry...

Can someone give me an example of how to list an unknown number of
subkeys under a key, and put the key names in one column of a
listbox, and the key values in another column of a listbox?

Thanks!


Look at GetSubKeyNames(), and GetValueNames of the RegistryKey object.

HTH,
Eric


I know this isn't right but I know I'm close.
What do I need to do to fix this?

string[] strKeys;
string[] strValues;
RegistryKey rk = Registry.CurrentUser;
rk = rk.OpenSubKey("Software\\Microsoft\\Windows\\Curre ntVersion
\\Internet Settings");
strKeys = rk.GetSubKeyNames();
for (int i = 0; i < strKeys.Length; i++)
rk = strKeys.GetValue(i);
listBox.Items.Add(rk.GetValueNames);

Nov 16 '05 #3

"vbMark" <no@email.com> wrote in message
news:Xn************************@130.133.1.4...
I know this isn't right but I know I'm close.
What do I need to do to fix this?

string[] strKeys;
string[] strValues;
RegistryKey rk = Registry.CurrentUser;
rk = rk.OpenSubKey("Software\\Microsoft\\Windows\\Curre ntVersion
\\Internet Settings");
strKeys = rk.GetSubKeyNames();
for (int i = 0; i < strKeys.Length; i++)
rk = strKeys.GetValue(i);
listBox.Items.Add(rk.GetValueNames);

You are getting closer. One thing is, I'm not really sure what you're trying
to show to the user, so it's hard to be more helpful. But for starters, you
should understand that a key can hold subkeys, which can hold subkeys, etc,
etc; which at the bottom hold name value pairs. So not all keys will have a
single value which means anything if you can figure out a way to display it
in one line of a list box. In other words the depth of the registry is
unknown (at least to me.)

Now, your last try in code. You wrote RegistryKey rk = Registry.CurrentUser;
rk = rk.OpenSubKey("Software\\Microsoft\\Windows\\Curre ntVersion
\\Internet Settings");
You're setting rk twice in two lines. Not necessary. (watch word wrap)

RegistryKey rk =
Registry.CurrentUser.OpenSubKey(@"Software\\Micros oft\\Windows\\CurrentVersi
on\\Internet Settings");
Console.WriteLine("Subkeys: " + rk.SubKeyCount); // = 10 on my machine
Console.WriteLine("Values: " + rk.ValueCount); //= 30 on my machine

then you have strKeys = rk.GetSubKeyNames();

which returns all the subkeys which are like folders, and which may be what
you want, but I'm not sure. The names you get are other keys, which can
contain values and other keys. So I'm not sure what you get with the for
loop but it's probably not what you want.

On my machine, the key you open has ten subkeys, and 30 values, which are
different. The subkeys are like subfolders, and the values like files.

Once you figure out which it is you want, the subkeys or the values for a
key, you can load the list box using just two lines like
string[] keys = rs.GetSubKeyNames();
listBox1.DataSource = keys;

HTH
Eric
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: vbMark | last post by:
Here's my code: string strKeys; RegistryKey rk = Registry.CurrentUser; RegistryKey val = Registry.CurrentUser; string sLocation = "Software\\Microsoft\\Windows\\CurrentVersion \\Internet...
2
by: Allen | last post by:
Hey all, I have a question for you all. I'm learning vb.net and need some help. I have two classes one named Customers and one named CustomersDA. I have to go though Customer for everything. I have...
16
by: Allen | last post by:
I have a class that returns an arraylist. How do I fill a list box from what is returned? It returns customers which is a arraylist but I cant seem to get the stuff to fill a list box. I just...
1
by: Jonny | last post by:
Hi All I am writing a small app that enumerates a certain registry key & then adds the key values to a listbox When I select one in the listbox & click the delete button I want to delete that...
6
by: JOSII | last post by:
Getting a string of boolean value into and out of the registry is no problem. Here's the problem: Although you can place an object into the registry and retreive it, I need to place an ArrayList...
0
by: raypjr | last post by:
Hi everyone. I'm new here and hope I can get a little advice on how to list my array into a ListBox. I have my structure and array of structures. I need help with a For Loop that will list the...
2
by: raypjr | last post by:
Hi everyone. I'm new here and hope I can get a little advice on how to list my array into a ListBox. I have my structure and array of structures. I need help with a For Loop that will list the...
2
by: registry | last post by:
<%@Language="VBSCRIPT" CODEPAGE="1252"%> <html> <head> <title>Registry Network Hospital Detail</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script...
45
by: angelicdevil | last post by:
i have 2 tables 1 is status_type with field name status and other is users with field username and status now i want that the first listbox lists all status from status type ( this i have achieved...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.