Reputation: 443
When using Registry.GetValue(key, name, null)
, instead of:
C:\Windows\system32
I would like to retrieve the raw registry entry:
%SystemRoot%\system32
This is possible in C with WinAPI, but I don't see a way to do that with .NET.
Upvotes: 2
Views: 837
Reputation: 32713
You need to pass it RegistryValueOptions.DoNotExpandEnvironmentNames
. For example:
var key = @"SOFTWARE\Classes\.library-ms\ShellNew";
var name = "IconPath";
var regval = Registry.LocalMachine.OpenSubKey(key).GetValue(name, "",
RegistryValueOptions.DoNotExpandEnvironmentNames);
Console.WriteLine(regval);
output is: %SystemRoot%\System32\imageres.dll,-1001
Upvotes: 6
Reputation: 37060
From what I can tell, it does what you want by default:
Registry.SetValue(@"HKEY_CURRENT_USER\dummy", "pathTest", @"%SystemRoot%\system32");
Console.WriteLine(Registry.GetValue(@"HKEY_CURRENT_USER\dummy", "pathTest", null));
// Output:
// %SystemRoot%\system32
Upvotes: 0