简体   繁体   中英

How to edit registry value when I dont know full name of a field?

这里

On the screenshot is what I am dealing with basically I know don't know the second part of the name before my game launches because its generated randomly based on monitor ID or something.

  1. I would like to check if the key exist by partial name
  2. Get full name if its found
  3. Set my value for it

Currently I use this and its simply not possible to do it this way I think.

RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\AAA\MyApp\test\", false);

if (key != null)
{
    return (string)key.GetValue("Screenmanager Resolution ....");
}
else
{
    return null;
}

I would then like to set the value myself like

key.SetValue("Screenmanager Resolution Width_h182942802", 1024, RegistryValueKind.DWord);

You can get the value names with GetValueNames() and then see if the "Screen Resolution *" value exists:

string[] valueNames = key.GetValueNames();
string valueName = valueNames.FirstOrDefault(s => s.StartsWith("Screenmanager Resolution Width_"));
if(valueName != null)
{
    return key.GetValue(valueName);
}

or without LINQ:

foreach(string valueName in key.GetValueNames())
{
    if(valueName.StartsWith("Screenmanager Resolution Width_"))
        return key.GetValue(valueName);
}
return null;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM