跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

wsl_util_windows.go

43 行 · 1008 B历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package windows
5
6import (
7 "context"
8 "fmt"
9 "regexp"
10 "strings"
11)
12
13// vmIDRegex is a regular expression to extract the VM ID from the command line of wslhost.exe.
14var vmIDRegex = regexp.MustCompile(`--vm-id\s\{(?P<vmID>.{36})\}`)
15
16// GetInstanceVMID returns the VM ID of a running WSL instance.
17func GetInstanceVMID(ctx context.Context, instanceName string) (string, error) {
18 distroID, err := GetDistroID(instanceName)
19 if err != nil {
20 return "", err
21 }
22
23 cmdLines, err := GetProcessCommandLine(ctx, "wslhost.exe")
24 if err != nil {
25 return "", err
26 }
27
28 vmID := ""
29 for _, cmdLine := range cmdLines {
30 if strings.Contains(cmdLine, distroID) {
31 if matches := vmIDRegex.FindStringSubmatch(cmdLine); matches != nil {
32 vmID = matches[vmIDRegex.SubexpIndex("vmID")]
33 break
34 }
35 }
36 }
37
38 if vmID == "" {
39 return "", fmt.Errorf("failed to find VM ID for instance %#q", instanceName)
40 }
41
42 return vmID, nil
43}