Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6475977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:46:09+00:00 2026-05-25T06:46:09+00:00

I’m learning as I go with c# and I have been stuck with some

  • 0

I’m learning as I go with c# and I have been stuck with some code for a few weeks now and I’m hoping an experienced programmer can help.

Here is the scenario: When one connects to the remote computers’ registry you only get HKEY_LOCAL_MACHINE & HKEY_USERS. Now HKEY_USERS has a range of sub keys that related to the users profiles registry stored on the machine but is only displays it by numbers instead of Jo’s registry or John’s registry, hope you see where I’m going with this. So, using the code below provides one with the users profile name which is in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList and the sub key it’s stored in (distinguish by numbers) is the same sub key in HKEY_USERS…bingo.

Please note: This line of code if (!(sk.GetValue("Guid") == null)) ie.”Guid” is only present in a domain environment within the Profile list sub key and has a value called “Guid”. Because there are various Sub keys listed, I only want the ones which is a users profile. On my home machine I add the sub key in to make the code work.

using System;
using System.Windows.Forms;
using Microsoft.Win32;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            //http://www.dreamincode.net/code/snippet1995.htm

            //The registry key:
            string SoftwareKey = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList";
            using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey))
            {
                foreach (string skName in rk.GetSubKeyNames())
                {
                    using (RegistryKey sk = rk.OpenSubKey(skName))
                    {
                        try
                        {
                            if (!(sk.GetValue("Guid") == null))
                            {
                                string UserProfile;
                                string UserProfileComboBox;
                                string Software = null;
                                UserProfile = Software += sk.GetValue("ProfileImagePath"); 
                                UserProfileComboBox = UserProfile.Substring(9); //this reduces C:\Users\Home to Home. (0, 8) would have provide C:\Users
                                comboBox1.Items.Add(UserProfileComboBox);

                                //This messagebox displays the sub key I need when the userprofile is selected from the checkbox
                                MessageBox.Show(UserProfile + "    " + skName);
                             }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);  
                        }
                    }
                }
            }
        }
    }
}

In the above code I used: UserProfile.Substring(9) to reduce C:\Users\Home to just Home which is disable in the image below:

enter image description here

I’ve also added the following line of code to display the results to a message box for your understanding: MessageBox.Show(UserProfile + " " + skName);

What I would like to be able to do is…when I select the User profile from the combo box that the code knows which HKEY_USER subkey it relates too eg. S-1-5-21-340336367-1635450098-906894100-1008 (hkeyuserprofile) so I can do the registry key changes later:

CHANGE:

using (RegistryKey test = registry.Users.OpenSubKey(@"Software\Policies\Microsoft\..."))

To:

string hkeyuserprofile;

using (RegistryKey test = registry.Users.OpenSubKey(hkeyuserprofile + @"\Software\Policies\Microsoft\...")

Any help would be greatly appreciate! 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:46:09+00:00Added an answer on May 25, 2026 at 6:46 am

    You can accomplish this in a couple of different ways. I’ll show you two, but the first is preferred over the second. (I realized after writing this the second way is not applicable, so I have refrained from adding it)

    Databinding

    The nice thing about most of the collection controls is that they have a fairly decent data-binding mechanism built into them. You can leverage this to bind the control to a collection of more strongly typed Objects for future retrieval.

    First thing is first, you need an object that represents the information you want:

    public class RegKeyInfo
    {
        public String SubKeyPath { get; set; }
        public String Name { get; set; }
    } 
    

    So now you have a type that will store both the derived name you want, and the SubKeyPath for later use.

    Now we need to tell the combobox how it should handle this kind of object. We can set that up in the Form Constructor. Normally you could do this via the designer, but it’s easier to show you here.

    public Form1()
    {
        InitializeComponent();
    
        comboBox1.ValueMember = "SubKeyPath";
        comboBox1.DisplayMember = "Name";
    }
    

    Now you have told the ComboBox that when you give it an Object, it should look for a property called “Name” and use that for the display, and use the property “SubKeyPath” for the Value.

    Instead of adding items manually to the ComboBox, we are going to create a collection of our RegKeyInfo type, and “Bind” it to the ComboBox.

    private void Form1_Load(object sender, EventArgs e)
    {
        //http://www.dreamincode.net/code/snippet1995.htm
        //Declare the string to hold the list:
    
        var keys = new List<RegKey>();
    
        //Snip...
    
        UserProfileComboBox = UserProfile.Substring(9);
    
        keys.Add(new RegKey {
            Name = UserProfileComboBox,
            KeyPath = skName
        });
    
        //Snip... 
    
        comboBox1.DataSource = keys;
    }
    

    The big difference here is making use of the DataSource property, which tells the ComboBox to use data-binding based on the information you have given it.

    When someone selects a value from the ComboBox, you can access the SelectedValue property and retrive the SubKeyPath that it is bound to. Try adding in this event handler to the SelectedValueChanged event to see what I’m talking about:

    void comboBox1_SelectedValueChanged(object sender, EventArgs e)
    {
        MessageBox.Show(comboBox1.SelectedValue as String);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.