473,326 Members | 2,076 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,326 software developers and data experts.

Registry and TreeView

Greetings,

I'm creating a little program that acts as a glorified Registry explorer.
The TreeView doesn't allow you to show a plus sign unless a node has child
nodes, so I need to determine whether a registry key has subkeys and add a
dummy childnode. The way I'm doing this is to populate the child nodes as
the parent is expanded.

However, there are some serious performance implications. First, when I
pouplate the HKEY_CLASSES_ROOT, it takes 3 seconds to add all the subkeys to
the hive. But if I determine whether those subkeys have subkeys, it takes
49 minutes to populate the HIVE. This is obviously unacceptable. So I'm
left with two choices: 1) figure out a more efficient way to determine and
populate the data, or 2) use C++. Every reg explorer I've ever seen takes
milliseconds to populate the nodes as you expand them, and neither of these
programs are written in C#.

Does anyone here know a better approach? Keep in mind, I'm not populate the
subkeys. I'm only determing whether the subkeys have subkeys (at the level
currently visible) and adding a dummy node so you can get the [+] / [-]
symbol to expand/contract the nodes in the TreeView.

Is it the TreeView that's so slow or the Registry objects in the Win32
namespace? I don't have access to a decent profiler so its hard for me to
tell.
Thanks,
Shawn
Dec 22 '05 #1
8 4603
There must be something in your code that causes it to take that long. I
wrote a similar application some time ago in C# running on .NET 1.1. I tried
it out right now and it took about 4 seconds to list all keys in HKCR\CLSID,
and I expect that this is the largest one. Note that I'm also doing the
check for subkeys and use the same approach - insert a dummy node if there's
at least one subkey and add the subkeys in the BeforeExpand event.

Could you post the actual code populating the tree view?

Michael
"Shawn B." <le****@html.com> schrieb im Newsbeitrag
news:uM**************@TK2MSFTNGP09.phx.gbl...
Greetings,

I'm creating a little program that acts as a glorified Registry explorer.
The TreeView doesn't allow you to show a plus sign unless a node has child
nodes, so I need to determine whether a registry key has subkeys and add a
dummy childnode. The way I'm doing this is to populate the child nodes as
the parent is expanded.

However, there are some serious performance implications. First, when I
pouplate the HKEY_CLASSES_ROOT, it takes 3 seconds to add all the subkeys
to the hive. But if I determine whether those subkeys have subkeys, it
takes 49 minutes to populate the HIVE. This is obviously unacceptable.
So I'm left with two choices: 1) figure out a more efficient way to
determine and populate the data, or 2) use C++. Every reg explorer I've
ever seen takes milliseconds to populate the nodes as you expand them, and
neither of these programs are written in C#.

Does anyone here know a better approach? Keep in mind, I'm not populate
the subkeys. I'm only determing whether the subkeys have subkeys (at the
level currently visible) and adding a dummy node so you can get the [+] /
[-] symbol to expand/contract the nodes in the TreeView.

Is it the TreeView that's so slow or the Registry objects in the Win32
namespace? I don't have access to a decent profiler so its hard for me to
tell.
Thanks,
Shawn

Dec 22 '05 #2
Money says he's using Nodes.Add() instead of Nodes.AddRange(). That
would be key in this kind of situation.

Jason Newell
Michael Höhne wrote:
There must be something in your code that causes it to take that long. I
wrote a similar application some time ago in C# running on .NET 1.1. I tried
it out right now and it took about 4 seconds to list all keys in HKCR\CLSID,
and I expect that this is the largest one. Note that I'm also doing the
check for subkeys and use the same approach - insert a dummy node if there's
at least one subkey and add the subkeys in the BeforeExpand event.

Could you post the actual code populating the tree view?

Michael
"Shawn B." <le****@html.com> schrieb im Newsbeitrag
news:uM**************@TK2MSFTNGP09.phx.gbl...
Greetings,

I'm creating a little program that acts as a glorified Registry explorer.
The TreeView doesn't allow you to show a plus sign unless a node has child
nodes, so I need to determine whether a registry key has subkeys and add a
dummy childnode. The way I'm doing this is to populate the child nodes as
the parent is expanded.

However, there are some serious performance implications. First, when I
pouplate the HKEY_CLASSES_ROOT, it takes 3 seconds to add all the subkeys
to the hive. But if I determine whether those subkeys have subkeys, it
takes 49 minutes to populate the HIVE. This is obviously unacceptable.
So I'm left with two choices: 1) figure out a more efficient way to
determine and populate the data, or 2) use C++. Every reg explorer I've
ever seen takes milliseconds to populate the nodes as you expand them, and
neither of these programs are written in C#.

Does anyone here know a better approach? Keep in mind, I'm not populate
the subkeys. I'm only determing whether the subkeys have subkeys (at the
level currently visible) and adding a dummy node so you can get the [+] /
[-] symbol to expand/contract the nodes in the TreeView.

Is it the TreeView that's so slow or the Registry objects in the Win32
namespace? I don't have access to a decent profiler so its hard for me to
tell.
Thanks,
Shawn


Dec 22 '05 #3
> Money says he's using Nodes.Add() instead of Nodes.AddRange(). That would
be key in this kind of situation.


Yes I am. I'll have to redo the code for AddRange() if its really that much
more efficient. My code is very simple, the relevant part is:

if (canContinue == true)
{
string[] names = regKey.GetSubKeyNames();

tvwRegistryKeys.BeginUpdate();

foreach (string key in names)
{
regKey.OpenSubKey(path + @"\" + key);
TreeNode child = new TreeNode(key);

if (regKey.SubKeyCount > 0)
{
TreeNode childNode = new TreeNode("*");
child.Nodes.Add(childNode);
}

regKey.Close();
node.Nodes.Add(child);
}

regKey.Close();

tvwRegistryKeys.EndUpdate();
}
Thanks,
Shawn
Dec 23 '05 #4
Hi Shawn,

I agree with Jason that AddRange is preferable, but your problem clearly is
different. In your foreach loop you do a call to RegistryKey.OpenSubKey but
don't store the result in any variable:
foreach (string key in names)
{
regKey.OpenSubKey(path + @"\" + key);
Now that means that the next block will always operate on the same registry
key:
if (regKey.SubKeyCount > 0)
{
TreeNode childNode = new TreeNode("*");
child.Nodes.Add(childNode);
}


If this registry key is HKEY_CLASSES_ROOT, then regKey.SubKeyCount will take
an enormous amount of time to complete and you're calling it over and over.

Try the following and I'm quite sure that your tree is populated in a few
seconds. After you've verified that, you should go for AddRange to improve
it furhter.

if (canContinue == true)
{
string[] names = regKey.GetSubKeyNames();
tvwRegistryKeys.BeginUpdate();

foreach (string key in names)
{
RegistryKey regSubkey = regKey.OpenSubKey(path + @"\" + key);
TreeNode child = new TreeNode(key);

if (regSubkey.SubKeyCount > 0)
{
TreeNode childNode = new TreeNode("*");
child.Nodes.Add(childNode);
}

node.Nodes.Add(child);
regSubkey.Close();
}

regKey.Close();
}

Michael
"Shawn B." <le****@html.com> schrieb im Newsbeitrag
news:OH**************@TK2MSFTNGP14.phx.gbl...
Money says he's using Nodes.Add() instead of Nodes.AddRange(). That
would be key in this kind of situation.


Yes I am. I'll have to redo the code for AddRange() if its really that
much more efficient. My code is very simple, the relevant part is:

if (canContinue == true)
{
string[] names = regKey.GetSubKeyNames();

tvwRegistryKeys.BeginUpdate();

foreach (string key in names)
{
regKey.OpenSubKey(path + @"\" + key);
TreeNode child = new TreeNode(key);

if (regKey.SubKeyCount > 0)
{
TreeNode childNode = new TreeNode("*");
child.Nodes.Add(childNode);
}

regKey.Close();
node.Nodes.Add(child);
}

regKey.Close();

tvwRegistryKeys.EndUpdate();
}
Thanks,
Shawn

Dec 23 '05 #5
Michael,

If you're interested, I threw together a little C# 2005 regedit program
to show you what I'm talking about. I compared it to the Windows
regedit and it's slightly slower but nothing like what you described. I
don't know that you can get much faster with .NET. Let me know if you
have any questions.

You can download the source from my website.

www.jasonnewell.net/public/Examples/Regedit.zip

Jason Newell
Michael Höhne wrote:
Hi Shawn,

I agree with Jason that AddRange is preferable, but your problem clearly is
different. In your foreach loop you do a call to RegistryKey.OpenSubKey but
don't store the result in any variable:

foreach (string key in names)
{
regKey.OpenSubKey(path + @"\" + key);

Now that means that the next block will always operate on the same registry
key:

if (regKey.SubKeyCount > 0)
{
TreeNode childNode = new TreeNode("*");
child.Nodes.Add(childNode);
}

If this registry key is HKEY_CLASSES_ROOT, then regKey.SubKeyCount will take
an enormous amount of time to complete and you're calling it over and over.

Try the following and I'm quite sure that your tree is populated in a few
seconds. After you've verified that, you should go for AddRange to improve
it furhter.

if (canContinue == true)
{
string[] names = regKey.GetSubKeyNames();
tvwRegistryKeys.BeginUpdate();

foreach (string key in names)
{
RegistryKey regSubkey = regKey.OpenSubKey(path + @"\" + key);
TreeNode child = new TreeNode(key);

if (regSubkey.SubKeyCount > 0)
{
TreeNode childNode = new TreeNode("*");
child.Nodes.Add(childNode);
}

node.Nodes.Add(child);
regSubkey.Close();
}

regKey.Close();
}

Michael
"Shawn B." <le****@html.com> schrieb im Newsbeitrag
news:OH**************@TK2MSFTNGP14.phx.gbl...
Money says he's using Nodes.Add() instead of Nodes.AddRange(). That
would be key in this kind of situation.


Yes I am. I'll have to redo the code for AddRange() if its really that
much more efficient. My code is very simple, the relevant part is:

if (canContinue == true)
{
string[] names = regKey.GetSubKeyNames();

tvwRegistryKeys.BeginUpdate();

foreach (string key in names)
{
regKey.OpenSubKey(path + @"\" + key);
TreeNode child = new TreeNode(key);

if (regKey.SubKeyCount > 0)
{
TreeNode childNode = new TreeNode("*");
child.Nodes.Add(childNode);
}

regKey.Close();
node.Nodes.Add(child);
}

regKey.Close();

tvwRegistryKeys.EndUpdate();
}
Thanks,
Shawn


Dec 23 '05 #6
Sorry, I meant Shawn in my last post.

Jason Newell

Jason Newell wrote:
Michael,

If you're interested, I threw together a little C# 2005 regedit program
to show you what I'm talking about. I compared it to the Windows
regedit and it's slightly slower but nothing like what you described. I
don't know that you can get much faster with .NET. Let me know if you
have any questions.

You can download the source from my website.

www.jasonnewell.net/public/Examples/Regedit.zip

Jason Newell
Michael Höhne wrote:
Hi Shawn,

I agree with Jason that AddRange is preferable, but your problem
clearly is different. In your foreach loop you do a call to
RegistryKey.OpenSubKey but don't store the result in any variable:

foreach (string key in names)
{
regKey.OpenSubKey(path + @"\" + key);


Now that means that the next block will always operate on the same
registry key:

if (regKey.SubKeyCount > 0)
{
TreeNode childNode = new TreeNode("*");
child.Nodes.Add(childNode);
}


If this registry key is HKEY_CLASSES_ROOT, then regKey.SubKeyCount
will take an enormous amount of time to complete and you're calling it
over and over.

Try the following and I'm quite sure that your tree is populated in a
few seconds. After you've verified that, you should go for AddRange to
improve it furhter.

if (canContinue == true)
{
string[] names = regKey.GetSubKeyNames();
tvwRegistryKeys.BeginUpdate();

foreach (string key in names)
{
RegistryKey regSubkey = regKey.OpenSubKey(path + @"\" + key);
TreeNode child = new TreeNode(key);

if (regSubkey.SubKeyCount > 0)
{
TreeNode childNode = new TreeNode("*");
child.Nodes.Add(childNode);
}

node.Nodes.Add(child);
regSubkey.Close();
}

regKey.Close();
}

Michael
"Shawn B." <le****@html.com> schrieb im Newsbeitrag
news:OH**************@TK2MSFTNGP14.phx.gbl...
Money says he's using Nodes.Add() instead of Nodes.AddRange(). That
would be key in this kind of situation.
Yes I am. I'll have to redo the code for AddRange() if its really
that much more efficient. My code is very simple, the relevant part is:

if (canContinue == true)
{
string[] names = regKey.GetSubKeyNames();

tvwRegistryKeys.BeginUpdate();

foreach (string key in names)
{
regKey.OpenSubKey(path + @"\" + key);
TreeNode child = new TreeNode(key);

if (regKey.SubKeyCount > 0)
{
TreeNode childNode = new TreeNode("*");
child.Nodes.Add(childNode);
}

regKey.Close();
node.Nodes.Add(child);
}

regKey.Close();

tvwRegistryKeys.EndUpdate();
}
Thanks,
Shawn


Dec 23 '05 #7
Everytime I run it I keept getting "Object reference not set to an instance
of an object when it tries to return an instance by OpenSubKey(...); The
key path looks valid, I'm not sure what to do.

Thanks,
Shawn
"Michael Höhne" <mi************@nospam.nospam> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Hi Shawn,

I agree with Jason that AddRange is preferable, but your problem clearly
is different. In your foreach loop you do a call to RegistryKey.OpenSubKey
but don't store the result in any variable:
foreach (string key in names)
{
regKey.OpenSubKey(path + @"\" + key);


Now that means that the next block will always operate on the same
registry key:
if (regKey.SubKeyCount > 0)
{
TreeNode childNode = new TreeNode("*");
child.Nodes.Add(childNode);
}


If this registry key is HKEY_CLASSES_ROOT, then regKey.SubKeyCount will
take an enormous amount of time to complete and you're calling it over and
over.

Try the following and I'm quite sure that your tree is populated in a few
seconds. After you've verified that, you should go for AddRange to improve
it furhter.

if (canContinue == true)
{
string[] names = regKey.GetSubKeyNames();
tvwRegistryKeys.BeginUpdate();

foreach (string key in names)
{
RegistryKey regSubkey = regKey.OpenSubKey(path + @"\" + key);
TreeNode child = new TreeNode(key);

if (regSubkey.SubKeyCount > 0)
{
TreeNode childNode = new TreeNode("*");
child.Nodes.Add(childNode);
}

node.Nodes.Add(child);
regSubkey.Close();
}

regKey.Close();
}

Michael
"Shawn B." <le****@html.com> schrieb im Newsbeitrag
news:OH**************@TK2MSFTNGP14.phx.gbl...
Money says he's using Nodes.Add() instead of Nodes.AddRange(). That
would be key in this kind of situation.


Yes I am. I'll have to redo the code for AddRange() if its really that
much more efficient. My code is very simple, the relevant part is:

if (canContinue == true)
{
string[] names = regKey.GetSubKeyNames();

tvwRegistryKeys.BeginUpdate();

foreach (string key in names)
{
regKey.OpenSubKey(path + @"\" + key);
TreeNode child = new TreeNode(key);

if (regKey.SubKeyCount > 0)
{
TreeNode childNode = new TreeNode("*");
child.Nodes.Add(childNode);
}

regKey.Close();
node.Nodes.Add(child);
}

regKey.Close();

tvwRegistryKeys.EndUpdate();
}
Thanks,
Shawn


Dec 24 '05 #8
Works like a champ. Now I'll just have to figure out what I'm doing wrong.
Thanks,
Shawn

http://www.zenofdotnet.com

"Jason Newell" <no****@nospam.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Michael,

If you're interested, I threw together a little C# 2005 regedit program to
show you what I'm talking about. I compared it to the Windows regedit and
it's slightly slower but nothing like what you described. I don't know
that you can get much faster with .NET. Let me know if you have any
questions.

You can download the source from my website.

www.jasonnewell.net/public/Examples/Regedit.zip

Jason Newell
Michael Höhne wrote:
Hi Shawn,

I agree with Jason that AddRange is preferable, but your problem clearly
is different. In your foreach loop you do a call to
RegistryKey.OpenSubKey but don't store the result in any variable:

foreach (string key in names)
{
regKey.OpenSubKey(path + @"\" + key);

Now that means that the next block will always operate on the same
registry key:

if (regKey.SubKeyCount > 0)
{
TreeNode childNode = new TreeNode("*");
child.Nodes.Add(childNode);
}

If this registry key is HKEY_CLASSES_ROOT, then regKey.SubKeyCount will
take an enormous amount of time to complete and you're calling it over
and over.

Try the following and I'm quite sure that your tree is populated in a few
seconds. After you've verified that, you should go for AddRange to
improve it furhter.

if (canContinue == true)
{
string[] names = regKey.GetSubKeyNames();
tvwRegistryKeys.BeginUpdate();

foreach (string key in names)
{
RegistryKey regSubkey = regKey.OpenSubKey(path + @"\" + key);
TreeNode child = new TreeNode(key);

if (regSubkey.SubKeyCount > 0)
{
TreeNode childNode = new TreeNode("*");
child.Nodes.Add(childNode);
}

node.Nodes.Add(child);
regSubkey.Close();
}

regKey.Close();
}

Michael
"Shawn B." <le****@html.com> schrieb im Newsbeitrag
news:OH**************@TK2MSFTNGP14.phx.gbl...
Money says he's using Nodes.Add() instead of Nodes.AddRange(). That
would be key in this kind of situation.

Yes I am. I'll have to redo the code for AddRange() if its really that
much more efficient. My code is very simple, the relevant part is:

if (canContinue == true)
{
string[] names = regKey.GetSubKeyNames();

tvwRegistryKeys.BeginUpdate();

foreach (string key in names)
{
regKey.OpenSubKey(path + @"\" + key);
TreeNode child = new TreeNode(key);

if (regKey.SubKeyCount > 0)
{
TreeNode childNode = new TreeNode("*");
child.Nodes.Add(childNode);
}

regKey.Close();
node.Nodes.Add(child);
}

regKey.Close();

tvwRegistryKeys.EndUpdate();
}
Thanks,
Shawn



Dec 24 '05 #9

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

Similar topics

42
by: lauren quantrell | last post by:
So many postings on not to use the treeview control, but nothing recently. Is it safe to swim there yet with Access 2000-Access 2003?
5
by: SoKool | last post by:
Can anyone point me to a site where I can get a free treeview control to use in ASP .NET or any tutorial that can help me build my own treeview control. I intend to use a treeview to generate a...
2
by: Steve Teeples | last post by:
Is there a way to pull up a windows registry editor within the propertygrid? I only want to look at the keys and values, not change them. -- Steve
3
by: Peter | last post by:
Hello, We are inserting a side menu to our application using a class that is writing HTML on all our pages. This is a part of the code as an example: writer.Write(" <table WIDTH=""100%""...
6
by: L.M | last post by:
Hello, I knew how to use the treeview under VB6. After migrating to .NET, well, I'm lost. I try to add a new node, either to the same level or as a child to a selected node in the treeview....
14
by: Mr.D | last post by:
How do I save/load the contents of a Treeview to a file? I have found several good examples written i VB6, but not a single one for VB.NET. Please help. ---- Tim
8
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the...
3
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance, it is GREATLY appreciated. I'm wondering if there is a way to duplicate a function in regedit of find and find next for keywords programmatically,...
8
by: ross m. greenberg | last post by:
I'm trying to emulate the look and feel of "RegEdit" under Visual Basic/VB.Net using Visual Studio 2005. Can anybody give me a pointer in the right direction: for example, what name spaces must I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.