3

I'm making a simple program to get emails from a pop3 server using VS2010. probably gonna use the open source OpenPOP for some of it. And its supposed to then save the email and attachments in a MS SQL database.

But the question is, while attached files are easy to download from the mail server, is there any way to scan the attached files? The small company im working at uses just Microsoft security essentials.

Have googled around, but couldn't seem to find any info on this matter.

jgauffin
  • 99,844
  • 45
  • 235
  • 372
  • 2
    Check if you can get your antivirus app to scan a file through command line parameters. Use that command line option with something like `Process.Start(..)` – Davio Nov 09 '12 at 13:42

1 Answers1

3

You can use:

"%ProgramFiles%\Microsoft Security Client\MpCmdRun.exe" -Scan -ScanType 3 -File "<Path>"

and check the return code.

Additional information:

-Scan [-ScanType value]
     0  Default, according to your configuration
     1  Quick scan
     2  Full system scan
     3  File and directory custom scan

        [-File <path>]
             Indicates the file or directory  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.

   Return code is
   0    if no malware is found or malware is successfully remediated and no
        additional user action is required
   2    if malware is found and not remediated or additional user action is
        required to complete remediation or there is error in scanning.
        Please check History for more information.
Paolo Moretti
  • 54,162
  • 23
  • 101
  • 92
  • Hi @Paolo I am not receiving result in integer format. Receiving result "Scanning xyz.pdf has no threats". Can please help me to figure out what's wrong with my code. C# code: var args = "-Scan -ScanType 3 -File " Process.start(@"c:\Program Files\Microsoft Security Client\MpCmdRun.exe", args ) It is opening a command prompt and showing result as follows: Scanning started.. Scanning Finished.. Scanning xyz.pdf has no threats. – Dreamer Dec 19 '19 at 14:02
  • @Dreamer how are you checking the return code? Did you try with with `process.ExitCode`? https://stackoverflow.com/a/1585375/63011 Feel free to update the answer with an actual code snippet if this solution works for you – Paolo Moretti Dec 19 '19 at 16:53
  • Thank you @Paolo, it's working. I got ExitCode value. Is there any possibility to get exit code other than 0 or 2? Is there any reference document to get exit code value and details? – Dreamer Dec 20 '19 at 10:41