github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zutil/utils_win.go (about) 1 //go:build windows 2 // +build windows 3 4 package zutil 5 6 import ( 7 "errors" 8 "syscall" 9 "unsafe" 10 ) 11 12 func IsDoubleClickStartUp() bool { 13 if name, err := GetParentProcessName(); err == nil && name == "explorer.exe" { 14 return true 15 } 16 return false 17 } 18 19 func GetParentProcessName() (string, error) { 20 snapshot, err := syscall.CreateToolhelp32Snapshot(syscall.TH32CS_SNAPPROCESS, 0) 21 if err != nil { 22 return "", err 23 } 24 defer syscall.CloseHandle(snapshot) 25 var procEntry syscall.ProcessEntry32 26 procEntry.Size = uint32(unsafe.Sizeof(procEntry)) 27 if err = syscall.Process32First(snapshot, &procEntry); err != nil { 28 return "", err 29 } 30 var ( 31 pid = uint32(syscall.Getpid()) 32 pName = make(map[uint32]string, 32) 33 parentId = uint32(1<<32 - 1) 34 ) 35 for { 36 pName[procEntry.ProcessID] = syscall.UTF16ToString(procEntry.ExeFile[:]) 37 if procEntry.ProcessID == pid { 38 parentId = procEntry.ParentProcessID 39 } 40 if s, ok := pName[parentId]; ok { 41 return s, nil 42 } 43 err = syscall.Process32Next(snapshot, &procEntry) 44 if err != nil { 45 return "", err 46 } 47 } 48 } 49 50 // MaxRlimit (not relevant on Windows) 51 func MaxRlimit() (int, error) { 52 return 0, errors.New("not relevant on Windows") 53 }