Silverlight 4 WScript.regrad无法读取Windows 7下注册表中的新添加值
我有一个Silverlight 4应用程序,在该应用程序中,我可以毫无问题地从HKLM分支读取现有注册表值,但如果我添加新值,读取将失败,出现Silverlight 4 WScript.regrad无法读取Windows 7下注册表中的新添加值,silverlight,c#-4.0,Silverlight,C# 4.0,我有一个Silverlight 4应用程序,在该应用程序中,我可以毫无问题地从HKLM分支读取现有注册表值,但如果我添加新值,读取将失败,出现FileNotFoundException。您可以在下面的代码中看到;第一次读取工作正常,但第二次读取我在注册表中添加的测试值失败 注意:我能够在Windows XP下阅读新添加的密钥;只是不在Windows7下 任何帮助都将不胜感激 if (Application.Current.InstallState == InstallState.Installe
FileNotFoundException
。您可以在下面的代码中看到;第一次读取工作正常,但第二次读取我在注册表中添加的测试值失败
注意:我能够在Windows XP下阅读新添加的密钥;只是不在Windows7下
任何帮助都将不胜感激
if (Application.Current.InstallState == InstallState.Installed && Application.Current.HasElevatedPermissions)
{
if (AutomationFactory.IsAvailable)
{
dynamic shell = AutomationFactory.CreateObject("WScript.shell");
try
{
var resa = shell.RegRead(@"HKLM\SOFTWARE\Microsoft\.NETFramework\InstallRoot");
var resb = shell.RegRead(@"HKLM\SOFTWARE\Microsoft\.NETFramework\Test");
var regValue = shell.RegRead(DbTypeRegKeyName);
var dbType = ExtractDbTypeFromId(regValue);
}
catch (FileNotFoundException fileNotFoundException)
{
throw new Exception(string.Format("Failed to read registry value '{0}' with error '{1}'.", DbTypeValueName, fileNotFoundException));
}
}
}
在32位版本的Windows下工作正常。结果表明,64位版本的Windows具有不同的注册表视图。在注册表中的WOW6432节点项下添加我的项解决了该问题