Skip to content

Modding-Forge/restartmgr.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

restartmgr

PyPI - Version PyPI - Python Version PyPI - License Tests

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.dll directly via ctypes. Zero runtime dependencies.


Installation

uv add restartmgr

or

pip install restartmgr

Python 3.12+ and Windows are required.


Quick start

Which processes lock a file?

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})")

Detailed result with reboot reason

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}")

Full session lifecycle

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()

License

MIT - see LICENSE.


About Modding Forge

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!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages