Registry.GetValue自动扩展环境变量 - 什么办法避免?环境变量、办法、Registry、GetValue

2023-09-04 00:47:07 作者:山盟虽在 锦书难托

在使用 Registry.GetValue(键,名称为null),而不是:

C:\Windows\system32

我想获取原始注册表项:

I would like to retrieve the raw registry entry:

%SystemRoot%\system32

这是可能的下用WinAPI的,但我不明白的方式来做到这一点与.NET。

This is possible in C with WinAPI, but I don't see a way to do that with .NET.

推荐答案

您需要通过它 RegistryValueOptions.DoNotExpandEnvironmentNames 。例如:

var key = @"SOFTWARE\Classes\.library-ms\ShellNew";
var name = "IconPath";

var regval = Registry.LocalMachine.OpenSubKey(key).GetValue(name, "",
RegistryValueOptions.DoNotExpandEnvironmentNames);

Console.WriteLine(regval);

输出为: %SYSTEMROOT%\ SYSTEM32 \ imageres.dll,-1001

output is: %SystemRoot%\System32\imageres.dll,-1001

 
精彩推荐
图片推荐