Skip to main content
net10.0net11.0

.NET wrapper for the Antimalware Scan Interface (AMSI)

Published
Sep 3, 2026
1mo ago
Total Downloads
56.9K
56,851

Install

dotnet add package Meziantou.Framework.Win32.Amsi --version 3.0.2
ProductVersions
.NET
net10.0net11.0

README

Meziantou.Framework.Win32.Amsi

Meziantou.Framework.Win32.Amsi is a .NET wrapper for the Antimalware Scan Interface (AMSI). AMSI lets an application submit content to the antimalware product installed on the machine before acting on it, which is useful when the application evaluates scripts, macros, or uploaded files.

Requirements

  • Windows 10 / Windows Server 2016 or later
  • An antimalware provider registered with AMSI. When no provider is registered, scans succeed and report the content as not detected.

Usage

Create a context per application and scan content with it:

using Meziantou.Framework.Win32;

using var context = AmsiContext.Create("MyApplication");

if (context.IsMalware(@"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*", "test.txt"))
{
    Console.WriteLine("Malware detected!");
}

Byte buffers are supported too:

var payload = File.ReadAllBytes("document.docm");
if (context.IsMalware(payload, "document.docm"))
{
    Console.WriteLine("Malware detected!");
}

When several scans belong together — the fragments of one script, or the parts of one upload — open a session so the provider can correlate them:

using var context = AmsiContext.Create("MyApplication");
using var session = context.CreateSession();

foreach (var fragment in fragments)
{
    if (session.IsMalware(fragment, "script.ps1"))
    {
        Console.WriteLine("Malware detected!");
        break;
    }
}

Dispose the session and the context when you are done with them.

Additional resources

Changes from Previous Version

No structural changes between v3.0.1 and v3.0.2.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

Compatibility metadata lists 2 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.