Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

As can be seen here, with a little help from my friends I was eventually able to update the registry in a .NET 4.5 app using this code:

RegistryKey reg64key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
RegistryKey reg_64bit_AppKey = reg64key.OpenSubKey(@"SOFTWAREAndroid Studio", true);
if (reg_64bit_AppKey != null)
{
    reg_64bit_AppKey.SetValue("StartMenuGroup", "Droidio", RegistryValueKind.String);
}
else
{
    MessageBox.Show("Cannot open registry");
}

...but trying to adapt that test code to work in my.NET 3.5 app doesn't work - it won't even compile. I changed "64" to "32" (it's a Windows CE / Compact Framework app), and changed the specific registry location and value I want to change like so:

private void UpdateRegistry()
{
    RegistryKey reg32key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
    RegistryKey reg_32bit_AppKey = reg32key.OpenSubKey(@"SOFTWAREMicrosoftWindows CE Services", true);
    if (reg_32bit_AppKey != null)
    {
        MessageBox.Show(String.Format("value was {0}", reg_32bit_AppKey.GetValue("GuestOnly")));
        reg_32bit_AppKey.SetValue("GuestOnly", 00000001, RegistryValueKind.DWord);
        MessageBox.Show(String.Format("value is now {0}", reg_32bit_AppKey.GetValue("GuestOnly")));
    }
    else
    {
        MessageBox.Show("Cannot open registry");
    }
}

...but, as noted, it doesn't compile. As can be seen here, OpenBaseKey is new with .NET 4, and I'm using .NET 3.5 (Compact Framework). RegistryHive also shows "red" in the IDE, but maybe that's because of the problems with OpenBaseKey (according to this, it should be available to me).

RegistryView, like OpenBaseKey, was not even a gleam in the .NET architect's eye at the time .NET 3.5 was released - it first appeared in .NET 4.

So how can I accomplish the same thing I'm doing in .NET 4.5 in .NET 3.5 (without benefit of OpenBaseKey and RegistryView and, perhaps, RegistryHive)?

UPDATE

It turns out I may be barking up the wrong tree with this attempt to update the "GuestOnly" setting.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
245 views
Welcome To Ask or Share your Answers For Others

1 Answer


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...