Skip to main content

Python ctypes bindings for the Windows Restart Manager API (rstrtmgr.dll)

Project description

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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

restartmgr-1.0.0.tar.gz (42.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

restartmgr-1.0.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file restartmgr-1.0.0.tar.gz.

File metadata

  • Download URL: restartmgr-1.0.0.tar.gz
  • Upload date:
  • Size: 42.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for restartmgr-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4738b4e20b4905f2673fab453c13db6deb6be3a9145bdeadfb063929e0b49a53
MD5 1cca05984a7bd939e7b37afe2f9c41df
BLAKE2b-256 a83ad7a8144c9e9e325f0e853c964485da24c112ac21f190a1ab01422777dc0a

See more details on using hashes here.

File details

Details for the file restartmgr-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: restartmgr-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for restartmgr-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8c269f74eb4379a3b3fda67e323fbf64c41646324c818720a91f100e1337413
MD5 98f6cae6e770ec242319bbbce0cf3ac6
BLAKE2b-256 750832a490bf7d9822999578bfcc6bd259c8a56071136920342a6609ed7d2462

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page