Resolving issue with Registry reads where values are not present.

This commit is contained in:
Mike Richmond
2016-08-04 13:15:34 -07:00
parent 6eb0f2d6c7
commit d3625f7662
@@ -762,19 +762,21 @@ namespace System.Management.Automation
return null;
}
// verify the value kind as a string
RegistryValueKind kind = regKey.GetValueKind(valueName);
object regValue = regKey.GetValue(valueName);
if (null != regValue)
{
// verify the value kind as a string
RegistryValueKind kind = regKey.GetValueKind(valueName);
if (kind == RegistryValueKind.ExpandString ||
kind == RegistryValueKind.String)
{
return regKey.GetValue(valueName) as string;
}
else
{
// The function expected a string, but got another type. This is a coding error or a registry key typing error.
return null;
if (kind == RegistryValueKind.ExpandString ||
kind == RegistryValueKind.String)
{
return regValue as string;
}
}
// The function expected a string, but got another type or the value doesn't exist.
return null;
}
}