-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegistryHelper.cs
69 lines (61 loc) · 2.31 KB
/
RegistryHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using Microsoft.Win32;
namespace EnumSDKs.Extracted
{
/// <summary>
/// Helper methods that simplify registry access.
/// </summary>
internal static class RegistryHelper
{
/// <summary>
/// Given a baseKey and a subKey, get all of the subkeys names.
/// </summary>
/// <param name="baseKey">The base registry key.</param>
/// <param name="subkey">The subkey</param>
/// <returns>An enumeration of strings.</returns>
internal static IEnumerable<string> GetSubKeyNames(RegistryKey baseKey, string subkey)
{
IEnumerable<string> subKeys = null;
using (RegistryKey subKey = baseKey.OpenSubKey(subkey))
{
if (subKey != null)
{
subKeys = subKey.GetSubKeyNames();
}
}
return subKeys;
}
/// <summary>
/// Given a baseKey and subKey, get the default value of the subKey.
/// </summary>
/// <param name="baseKey">The base registry key.</param>
/// <param name="subkey">The subkey</param>
/// <returns>A string containing the default value.</returns>
internal static string GetDefaultValue(RegistryKey baseKey, string subkey)
{
string value = null;
using (RegistryKey key = baseKey.OpenSubKey(subkey))
{
if (key?.ValueCount > 0)
{
value = (string)key.GetValue("");
}
}
return value;
}
/// <summary>
/// Given a hive and a hive view open the base key
/// RegistryKey baseKey = RegistryKey.OpenBaseKey(hive, view);
/// </summary>
/// <param name="hive">The hive.</param>
/// <param name="view">The hive view</param>
/// <returns>A registry Key for the given baseKey and view</returns>
internal static RegistryKey OpenBaseKey(RegistryHive hive, RegistryView view)
{
RegistryKey key = RegistryKey.OpenBaseKey(hive, view);
return key;
}
}
}