-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy path0012-get-vmid-from-registry.patch
40 lines (37 loc) · 1.54 KB
/
0012-get-vmid-from-registry.patch
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
--- wslbridge2/src/wslbridge2.cpp 2024-10-10 20:20:21.931891800 +0000
+++ wslbridge2-0.12/src/wslbridge2.cpp 2024-10-08 09:31:35.954145800 +0000
@@ -228,6 +228,26 @@ static void start_dummy(std::wstring wsl
CloseHandle(pi.hThread);
}
+bool GetIdFromRegistry(GUID *guid) {
+ HKEY hKeyRoot = HKEY_LOCAL_MACHINE;
+ std::wstring subKey = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\HostComputeService\\VolatileStore\\ComputeSystem";
+ HKEY hKey;
+ if (RegOpenKeyEx(hKeyRoot, subKey.c_str(), 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
+ DWORD index = 0;
+ WCHAR keyName[256];
+ DWORD keyNameSize = sizeof(keyName) / sizeof(keyName[0]);
+
+ while (RegEnumKeyEx(hKey, index, keyName, &keyNameSize, nullptr, nullptr, nullptr, nullptr) == ERROR_SUCCESS) {
+ RegCloseKey(hKey);
+ std::wstring id = L"{" + std::wstring(keyName) + L"}";
+ return IIDFromString(id.c_str(), guid) == S_OK;
+ }
+ RegCloseKey(hKey);
+ }
+ return false;
+}
+
+
int main(int argc, char *argv[])
{
/* Minimum requirement Windows 10 build 17763 aka. version 1809 */
@@ -387,8 +407,8 @@ int main(int argc, char *argv[])
if (LiftedWSLVersion)
start_dummy(wslPath, wslCmdLine, distroName, debugMode);
- const HRESULT hRes = GetVmId(&DistroId, &VmId, LiftedWSLVersion);
- if (hRes != 0)
+ const bool hRes = GetIdFromRegistry(&VmId);
+ if (!hRes)
fatal("GetVmId: %s\n", GetErrorMessage(hRes).c_str());
inputSock = win_vsock_create();