mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-11-23 20:36:33 +01:00
CA-196887: New function for reading registry key written by the installer
- When the installer writes HiddenFeatures registry entry, it specifies registry key HKMU, that means that it will be written in HKLM if the user selected "All Users" for installation, or to HKCU if the user selected "Just Me". - Added a new function to read an installed key by trying CurrentUser first, then Local Machine. This function specifies a registry view (RegistryView.Registry32) when it opens the key (On the 64-bit version of Windows, portions of the registry are stored separately for 32-bit and 64-bit applications. There is a 32-bit view for 32-bit applications and a 64-bit view for 64-bit applications). Signed-off-by: Mihaela Stoica <Mihaela.Stoica@citrix.com>
This commit is contained in:
parent
3601f8fba9
commit
a9d7d95f56
@ -271,7 +271,7 @@ namespace XenAdmin.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a key from XENCENTER_LOCAL_KEYS\k.
|
||||
/// Reads a key from HKEY_LOCAL_MACHINE\XENCENTER_LOCAL_KEYS\k.
|
||||
/// </summary>
|
||||
private static string ReadKey(string k)
|
||||
{
|
||||
@ -299,6 +299,46 @@ namespace XenAdmin.Core
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a key from hKey\XENCENTER_LOCAL_KEYS\k, targeting the 32-bit registry view
|
||||
/// </summary>
|
||||
private static string ReadKey(string k, RegistryHive hKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
RegistryKey masterKey = RegistryKey.OpenBaseKey(hKey, RegistryView.Registry32);
|
||||
masterKey = masterKey.OpenSubKey(XENCENTER_LOCAL_KEYS) ?? null;
|
||||
|
||||
if (masterKey == null)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
var v = masterKey.GetValue(k);
|
||||
return (v != null) ? v.ToString() : null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
masterKey.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.DebugFormat(@"Failed to read {0}\{1} from registry; assuming NULL.", XENCENTER_LOCAL_KEYS, k);
|
||||
log.Debug(e, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a key from XENCENTER_LOCAL_KEYS\k, trying CurrentUser first and then LocalMachine
|
||||
/// </summary>
|
||||
private static string ReadInstalledKey(string k)
|
||||
{
|
||||
var v = ReadKey(k, RegistryHive.CurrentUser);
|
||||
return (v != null) ? v : ReadKey(k, RegistryHive.LocalMachine);
|
||||
}
|
||||
|
||||
public static string HealthCheckIdentityTokenDomainName
|
||||
{
|
||||
get { return ReadKey(HEALTH_CHECK_IDENTITY_TOKEN_DOMAIN_NAME); }
|
||||
@ -331,7 +371,7 @@ namespace XenAdmin.Core
|
||||
|
||||
public static string HiddenFeatures
|
||||
{
|
||||
get { return ReadKey(HIDDEN_FEATURES); }
|
||||
get { return ReadInstalledKey(HIDDEN_FEATURES); }
|
||||
}
|
||||
|
||||
internal static bool CPSOptimizationHidden
|
||||
|
Loading…
Reference in New Issue
Block a user