-
Notifications
You must be signed in to change notification settings - Fork 0
/
RegistryManager.cs
59 lines (42 loc) · 1.39 KB
/
RegistryManager.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
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
namespace BISLib
{
internal class RegistryManager
{
public static bool IsPresent(string registryKey)
{
string[] keys = registryKey.Split('\\');
RegistryKey reg = Registry.LocalMachine;
if (keys[0] == "HKLM")
reg = Registry.LocalMachine;
if (keys[0] == "HKCU")
reg = Registry.CurrentUser;
for (int i = 1; i < keys.Length; i++)
{
if (Array.IndexOf(reg.GetSubKeyNames(), keys[i]) == -1)
return false;
reg = reg.OpenSubKey(keys[i]);
}
return true;
}
public static object GetValue(string registryKey)
{
string[] keys = registryKey.Split('\\');
RegistryKey reg = Registry.LocalMachine;
if (keys[0] == "HKLM")
reg = Registry.LocalMachine;
if (keys[0] == "HKCU")
reg = Registry.CurrentUser;
for (int i = 1; i < keys.Length - 1; i++)
{
if (Array.IndexOf(reg.GetSubKeyNames(), keys[i]) == -1)
return null;
reg = reg.OpenSubKey(keys[i]);
}
return reg.GetValue(keys[keys.Length - 1],"");
}
}
}