MSE v2 Command-Line Scanning
July 21, 2010 3 Comments
Microsoft Security Essentials (MSE) 2.0 adds command-line file scanning to its command-line interface.
MpCmdRun.exe is the command-line interface to MSE.
(Note that MSE has moved from “C:\Program Files\Microsoft Security Essentials” to “C:\Program Files\Microsoft Security Client”. And MpCmdRun.exe has moved to a subdirectory called Antimalware.)
In MSE v1, MpCmdRun was conspicuously missing an option to scan a file from a command line but the problem is rectified in MSE v2 beta.
The file scanning is a new sub-option of the –Scan argument.
-Scan [-ScanType value]
0 Default, according to your configuration
1 Quick scan
2 Full system scan
3 Single file custom scan
[-File ]
Indicates the file path to be scanned, only valid for custom scan
[-DisableRemediation]
This option is valid only for custom scan.
When specified:
- File exclusions are ignored.
- Archive files are scanned.
- Actions are not applied after detection.
- Event log entries are not written after detection.
- Detections from the custom scan are not displayed in the user
interface.
The usage is slightly awkward. It requires specifying –Scan –ScanType 3 –File <filename>.
A simple powershell function or a batch file.
Powershell
function Scan-File( $file )
{
$exe = Join-Path $env:ProgramFiles "Microsoft Security Client/Antimalware/MpCmdRun.exe"
& $exe -Scan -ScanType 3 -File $file
}
Batch
@echo off setlocal set path=%programfiles%\Microsoft Security Client\Antimalware;%path% cmd /c MpCmdRun.exe -Scan -ScanType 3 -File %1
Niftier PowerShell integration is possible by extending the work of the Scripting Guy’s Invoke-SecurityEssentials.ps1 script for MSE v1.0.