Skip to main content

Manage Microsoft Defender path exclusions from Python, CLI, or GUI.

Project description

py-win-mp-exclude

py-win-mp-exclude is a Windows package for adding, removing, and listing Microsoft Defender path exclusions from a CLI, a small GUI, or Python code.

The tool uses PowerShell's Defender cmdlets:

  • Add-MpPreference -ExclusionPath
  • Remove-MpPreference -ExclusionPath
  • Get-MpPreference

When a CLI subcommand or the GUI starts without administrator privileges, the program relaunches itself once through py-admin-launch. A hidden startup flag prevents repeated elevation attempts. --dry-run commands only print the PowerShell script and do not request elevation.

Installation

pip install py-win-mp-exclude

CLI

Add a file or folder exclusion:

win-mp-exclude add C:\path\to\file.exe
win-mp-exclude add C:\path\to\folder

Remove a file or folder exclusion:

win-mp-exclude remove C:\path\to\file.exe
win-mp-exclude remove C:\path\to\folder

List configured path exclusions:

win-mp-exclude list

Preview the PowerShell command without running it:

win-mp-exclude --dry-run add C:\path\to\folder

The package also installs the alias py-win-mp-exclude.

GUI

Launch the graphical interface:

win-mp-exclude-gui

The GUI can add exclusions, remove exclusions, remove a selected exclusion, list current exclusions, and preview the PowerShell command it will run. The package also installs the alias py-win-mp-exclude-gui.

Python API

The Python API exposes the same add, remove, list, and dry-run capabilities used by the CLI and GUI:

from win_mp_exclude import add_exclusion, list_exclusions, remove_exclusion

add_result = add_exclusion(r"C:\path\to\folder")
print(add_result.message)

for path in list_exclusions().exclusions:
    print(path)

remove_result = remove_exclusion(r"C:\path\to\folder")
print(remove_result.message)

Use dry_run=True to inspect the PowerShell script without applying a change:

from win_mp_exclude import add_exclusion

result = add_exclusion(r"C:\path\to\folder", dry_run=True)
print(result.script)

By default, Python mutating calls can request administrator elevation once. Pass elevate=False if your program wants to handle elevation itself.

Development

Build with Poetry:

poetry build

Publish with Poetry:

poetry publish

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

py_win_mp_exclude-0.2.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

py_win_mp_exclude-0.2.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file py_win_mp_exclude-0.2.1.tar.gz.

File metadata

  • Download URL: py_win_mp_exclude-0.2.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10

File hashes

Hashes for py_win_mp_exclude-0.2.1.tar.gz
Algorithm Hash digest
SHA256 a827713203d3294f949097a9083db6a99a5c8d92de2df6f1d80dd1cfbc419fd8
MD5 3e3583ba9b8211ba1055d16daf76ae43
BLAKE2b-256 3123935fbcfa9c74efca82f1c7a6deab1749aa0551946907fcda877f2dcd04f3

See more details on using hashes here.

File details

Details for the file py_win_mp_exclude-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: py_win_mp_exclude-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10

File hashes

Hashes for py_win_mp_exclude-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1ce34b572b46d1c0f296de0ef9142e76af9771d5ea8c05f032f2e8e15eb2762a
MD5 993765eac3933eaf7860e41d71a45cf4
BLAKE2b-256 151d107d006591add8d3e443ccbd1689295a61917150d761ef6c4b87cfd3314b

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