master
hpp 85 lines 2.97 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 registry.hpp
8
9 Abstract:
10
11 This is the header file for registry management helper functions.
12
13 --*/
14
15 #pragma once
16
17 #define LXSS_SERVICE_REGISTRY_PATH L"SYSTEM\\CurrentControlSet\\Services\\LxssManager"
18
19 namespace wsl::windows::common::registry {
20
21 void ClearSubkeys(_In_ HKEY Key);
22
23 wil::unique_hkey CreateKey(
24 _In_ HKEY Key, _In_ LPCWSTR KeyName, _In_ REGSAM AccessMask = (KEY_READ | KEY_WRITE), _Out_opt_ LPDWORD Disposition = nullptr, _In_ DWORD Options = 0);
25
26 bool DeleteKey(_In_ HKEY Key, _In_ LPCWSTR KeyName);
27
28 void DeleteKeyValue(_In_ HKEY Key, _In_ LPCWSTR KeyName);
29
30 void DeleteValue(_In_ HKEY Key, _In_ LPCWSTR KeyName);
31
32 std::vector<std::pair<GUID, std::wstring>> EnumGuidKeys(_In_ HKEY LxssKey);
33
34 std::map<std::wstring, wil::unique_hkey> EnumKeys(_In_ HKEY Key, _In_ DWORD SubkeyAccess);
35
36 std::vector<std::pair<std::wstring, DWORD>> EnumValues(_In_ HKEY Key);
37
38 std::map<std::wstring, std::wstring> EnumStringValues(_In_ HKEY Key);
39
40 DWORD GetMachinePolicyValue(_In_ LPCWSTR Name, HKEY lxssKey);
41
42 bool IsKeyVolatile(_In_ HKEY Key);
43
44 wil::unique_hkey OpenCurrentUser(_In_ REGSAM AccessMask = (KEY_READ | KEY_WRITE));
45
46 wil::unique_hkey OpenKey(_In_ HKEY Key, _In_ LPCWSTR SubKey, _In_ REGSAM AccessMask, _In_ DWORD Options = 0);
47
48 std::pair<wil::unique_hkey, HRESULT> OpenKeyNoThrow(_In_ HKEY Key, _In_ LPCWSTR SubKey, _In_ REGSAM AccessMask, _In_ DWORD Options = 0);
49
50 wil::unique_hkey OpenLxssMachineKey(REGSAM AccessMask = KEY_READ);
51
52 wil::unique_hkey OpenLxssUserKey();
53
54 wil::unique_hkey OpenOrCreateLxssDiskMountsKey(_In_ PSID UserSid);
55
56 void QueryInfo(
57 _In_ HKEY Key,
58 _In_opt_ DWORD* MaxSubKeySize = nullptr,
59 _In_opt_ DWORD* MaxValueNameSize = nullptr,
60 _In_opt_ DWORD* MaxValueDataSize = nullptr,
61 _Out_opt_ DWORD* SubKeyCount = nullptr,
62 _Out_opt_ DWORD* ValueCount = nullptr);
63
64 DWORD
65 ReadDword(_In_ HKEY Key, _In_opt_ LPCWSTR KeyName, _In_opt_ LPCWSTR ValueName, _In_ DWORD DefaultValue);
66
67 ULONG64
68 ReadQword(_In_ HKEY Key, _In_opt_ LPCWSTR KeyName, _In_opt_ LPCWSTR ValueName, _In_ ULONG64 DefaultValue);
69
70 std::wstring ReadString(_In_ HKEY Key, _In_opt_ LPCWSTR KeyName, _In_opt_ LPCWSTR ValueName, _In_opt_ LPCWSTR Default = nullptr);
71 std::optional<std::wstring> ReadOptionalString(_In_ HKEY Key, _In_opt_ LPCWSTR KeyName, _In_opt_ LPCWSTR ValueName);
72
73 std::vector<std::string> ReadStringSet(_In_ HKEY Key, _In_opt_ LPCWSTR KeyName, _In_opt_ LPCWSTR ValueName, _In_ const std::vector<std::string>& Default);
74
75 void WriteDword(_In_ HKEY Key, _In_ LPCWSTR SubKey, _In_ LPCWSTR KeyName, _In_ DWORD Value);
76
77 void WriteQword(_In_ HKEY Key, _In_ LPCWSTR SubKey, _In_ LPCWSTR KeyName, _In_ ULONG64 Value);
78
79 void WriteDefaultString(_In_ HKEY Key, _In_ LPCWSTR Value);
80
81 void WriteString(_In_ HKEY Key, _In_ LPCWSTR SubKey, _In_ LPCWSTR KeyName, _In_ LPCWSTR Value);
82
83 void WriteStringSet(_In_ HKEY Key, _In_ LPCWSTR SubKey, _In_ LPCWSTR KeyName, _In_ const std::vector<std::wstring>& StringSet);
84
85 } // namespace wsl::windows::common::registry