Various Scripts and Application Code Segments for .NET, VB, C#, C++, C, Java, JavaScript, HTML, Python, Perl, AutoIT, Batch, ASP Classic, Objective-C, Swift, Unreal Engine 4, Unity3D & others. Also contains numerous IT tidbits, procedures, and tricks including Technology Hacks on various platforms.
Sunday, October 10, 2010
Loading Registry into a tree in C#
This code is from my R2E program. It basically loads the local registry of a user into a tree control in C#. The tree is expandable only a few levels. Above is a screenshot of the tree.
private void ReadRegistry()
{
TreeNode rootNode = new TreeNode(Registry.ClassesRoot.Name, 0, 1);
string[] rootSubKeys = Registry.ClassesRoot.GetSubKeyNames();
foreach (string key in rootSubKeys)
{
TreeNode node = new TreeNode(key, 0, 1);
string[] subKeys = Registry.ClassesRoot.OpenSubKey(key).GetSubKeyNames();
foreach (string subKeysKey in subKeys)
{
node.Nodes.Add(subKeysKey, subKeysKey, 0, 1);
}
rootNode.Nodes.Add(node);
}
registryTreeView.Nodes.Add(rootNode);
TreeNode configNode = new TreeNode(Registry.CurrentConfig.Name, 0, 1);
string[] configSubKeys = Registry.CurrentConfig.GetSubKeyNames();
foreach (string key in configSubKeys)
{
TreeNode node = new TreeNode(key, 0, 1);
string[] subKeys =
Registry.CurrentConfig.OpenSubKey(key).GetSubKeyNames();
foreach (string subKeysKey in subKeys)
node.Nodes.Add(subKeysKey, subKeysKey, 0, 1);
configNode.Nodes.Add(node);
}
registryTreeView.Nodes.Add(configNode);
TreeNode currentUserNode = new TreeNode(Registry.CurrentUser.Name, 0, 1);
string[] currentUserSubKeys = Registry.CurrentUser.GetSubKeyNames();
foreach (string key in currentUserSubKeys)
{
TreeNode node = new TreeNode(key, 0, 1);
string[] subKeys = Registry.CurrentUser.OpenSubKey(key).GetSubKeyNames();
foreach (string subKeysKey in subKeys)
node.Nodes.Add(subKeysKey, subKeysKey, 0, 1);
currentUserNode.Nodes.Add(node);
}
registryTreeView.Nodes.Add(currentUserNode);
TreeNode localMachineNode = new TreeNode(Registry.LocalMachine.Name);
string[] localMachineSubKeys = Registry.LocalMachine.GetSubKeyNames();
foreach (string key in localMachineSubKeys)
{
TreeNode node = new TreeNode(key, 0, 1);
try
{
string[] subKeys =
Registry.LocalMachine.OpenSubKey(key, false).GetSubKeyNames();
foreach (string subKeysKey in subKeys)
node.Nodes.Add(subKeysKey, subKeysKey, 0, 1);
}
catch (Exception)
{
node.ImageIndex = 4;
node.SelectedImageIndex = 5;
}
localMachineNode.Nodes.Add(node);
}
Subscribe to:
Post Comments (Atom)
Generating "Always On Top" NSWindow in macOS across all detected displays
Also: Using UIKit & Cocoa Frameworks using Objective-C In m acOS or OS X , written in either Objective-C or Swift Langues, you m...
-
In Unreal Engine 4 you will eventually need Linear Interpolation between two values to do something like ping pong between two float val...
-
Recently Possess () has been deprecated from UE4 , and when writing classes based on AAIController you have to use the function OnPossess ...
-
Often we intermingle C++ and Blueprints, and need for the two to communicate. With Behavior Trees, using ENUMs is an everyday occurrence an...
No comments:
Post a Comment