Python ctypes bindings for the Windows Restart Manager API rstrtmgr.dll). Find out which processes are locking a file - and optionally shut them down and restart them - all from pure Python, no C extension required.
Windows only - calls
rstrtmgr.dlldirectly viactypes. Zero runtime dependencies.
uv add restartmgror
pip install restartmgrPython 3.12+ and Windows are required.
from pathlib import Path
from restartmgr import who_locks
lockers = who_locks(Path(r"C:\path\to\locked_file.txt"))
for p in lockers:
print(f"PID {p.pid} {p.app_name} ({p.app_type.name})")from restartmgr import get_locking_processes
result = get_locking_processes(r"C:\file_a.txt", r"C:\file_b.txt")
print(f"Reboot reason: {result.reboot_reason.name}")
for p in result.processes:
print(f" {p.pid} {p.app_name} restartable={p.restartable}")from restartmgr import RmSession, RmShutdownType
with RmSession() as session:
session.register_files([r"C:\path\to\file.txt"])
# Query which processes hold a lock
infos, reboot_reason = session.get_list()
for info in infos:
print(info.Process.dwProcessId, info.strAppName)
# Shut down those processes
session.shutdown(
action_flags=RmShutdownType.FORCE_SHUTDOWN,
)
# ... do your work on the file ...
# Restart the previously shut-down processes
session.restart()MIT - see LICENSE.
restartmgr was built for the Python tooling powering Modding Forge - a community dedicated to Skyrim modding. If you enjoy modding or want to connect with other modders, come say hi!