返回 DeepSeek-Reasonix
remote_window_owner_windows.go
根目录 / desktop / remote_window_owner_windows.go
1 //go:build windows
2
3 package main
4
5 import (
6 "context"
7 "errors"
8
9 "golang.org/x/sys/windows"
10 )
11
12 func waitForRemoteWindowOwnerExit(ctx context.Context, pid int) bool {
13 if pid <= 0 {
14 return true
15 }
16 handle, err := windows.OpenProcess(windows.SYNCHRONIZE, false, uint32(pid))
17 if err != nil {
18 return errors.Is(err, windows.ERROR_INVALID_PARAMETER)
19 }
20 defer windows.CloseHandle(handle)
21 for {
22 result, err := windows.WaitForSingleObject(handle, 250)
23 if err != nil {
24 return false
25 }
26 switch result {
27 case windows.WAIT_OBJECT_0:
28 return true
29 case uint32(windows.WAIT_TIMEOUT):
30 select {
31 case <-ctx.Done():
32 return false
33 default:
34 }
35 default:
36 return false
37 }
38 }
39 }
40
40 lines GO