Return the process creation FILETIME as an integer on Windows, ``None`` otherwise.
(pid: int)
| 105 | |
| 106 | @staticmethod |
| 107 | def _get_process_creation_time(pid: int) -> int | None: |
| 108 | """Return the process creation FILETIME as an integer on Windows, ``None`` otherwise.""" |
| 109 | if sys.platform != "win32": # pragma: win32 no cover |
| 110 | return None |
| 111 | import ctypes # pragma: win32 cover # noqa: PLC0415 |
| 112 | from ctypes import wintypes # noqa: PLC0415 |
| 113 | |
| 114 | kernel32 = ctypes.windll.kernel32 |
| 115 | handle = kernel32.OpenProcess(_WIN_PROCESS_QUERY_LIMITED_INFORMATION, 0, pid) |
| 116 | if not handle: |
| 117 | return None |
| 118 | try: |
| 119 | creation = wintypes.FILETIME() |
| 120 | exit_time = wintypes.FILETIME() |
| 121 | kernel_time = wintypes.FILETIME() |
| 122 | user_time = wintypes.FILETIME() |
| 123 | if not kernel32.GetProcessTimes( |
| 124 | handle, |
| 125 | ctypes.byref(creation), |
| 126 | ctypes.byref(exit_time), |
| 127 | ctypes.byref(kernel_time), |
| 128 | ctypes.byref(user_time), |
| 129 | ): |
| 130 | return None |
| 131 | finally: |
| 132 | kernel32.CloseHandle(handle) |
| 133 | return (creation.dwHighDateTime << 32) | creation.dwLowDateTime |
| 134 | |
| 135 | @staticmethod |
| 136 | def _write_lock_info(fd: int) -> None: |
no outgoing calls