Finding Registry Keys in C#

馋奶兔 提交于 2019-12-23 12:18:39

问题


I am working on a project that will allow me to delete the registry key from a Windows 7 PC. Specifically I am trying to make a program that will allow me to delete a profile from the machine via the ProfileList key. My problem is no matter what I try I can't seem to read the key correctly which I want to do before I start randomly deleting stuff. My code is

     RegistryKey OurKey = Registry.LocalMachine;
            OurKey = OurKey.OpenSubKey(@"SOFTWARE\Microsoft\WindowsNT\CurrentVersion\ProfileList", true);

            foreach (string Keyname in OurKey.GetSubKeyNames())
            {
                MessageBox.Show(Keyname);
            } 

This code runs but doesn't return anything (No MessageBox). Any ideas why not?

EDIT:

I got the top level keys to load thanks to you all but it does only show the folder/key names (Ex: S-1-5-21-3794573037-2687555854-1483818651-11661) what I need is to read the keys under that folder to see what the ProfilePath is. Would there be a better way to go about that?


回答1:


As pointed out by Lloyd, your path should use "Windows NT". In case of doubt, always use regedit to go inspect the registry manually.

Edit: To go with your edit, you can simply GetValue on the keys you find, the following code should do what you're looking for:

RegistryKey OurKey = Registry.LocalMachine;
OurKey = OurKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList", true);

foreach (string Keyname in OurKey.GetSubKeyNames())
{
    RegistryKey key = OurKey.OpenSubKey(Keyname);

    MessageBox.Show(key.GetValue("KEY_NAME").ToString()); // Replace KEY_NAME with what you're looking for
} 



回答2:


Windows NT

Please do not miss space



来源:https://stackoverflow.com/questions/13417955/finding-registry-keys-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!