mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-07 13:15:00 +00:00
feat: improve Windows parent process detection using psutil
This commit is contained in:
parent
e84caa48a0
commit
f1d1d1b37a
1 changed files with 11 additions and 8 deletions
|
@ -6,6 +6,7 @@ import sys
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
import pexpect
|
import pexpect
|
||||||
|
import psutil
|
||||||
|
|
||||||
|
|
||||||
def run_cmd(command, verbose=False, error_print=None):
|
def run_cmd(command, verbose=False, error_print=None):
|
||||||
|
@ -25,14 +26,16 @@ def run_cmd(command, verbose=False, error_print=None):
|
||||||
|
|
||||||
def get_windows_parent_process_name():
|
def get_windows_parent_process_name():
|
||||||
try:
|
try:
|
||||||
kernel32 = ctypes.windll.kernel32
|
current_process = psutil.Process()
|
||||||
h_process = kernel32.OpenProcess(0x0400, False, os.getppid())
|
while True:
|
||||||
exe_path = ctypes.create_unicode_buffer(260)
|
parent = current_process.parent()
|
||||||
kernel32.QueryFullProcessImageNameW(
|
if parent is None:
|
||||||
h_process, 0, exe_path, ctypes.byref(ctypes.c_ulong(260))
|
break
|
||||||
)
|
parent_name = parent.name().lower()
|
||||||
kernel32.CloseHandle(h_process)
|
if parent_name in ['powershell.exe', 'cmd.exe']:
|
||||||
return os.path.basename(exe_path.value).lower()
|
return parent_name
|
||||||
|
current_process = parent
|
||||||
|
return None
|
||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue