none
Anti virus scan before file upload scan RRS feed

  • Question

  • HI All,

    Anyone implemented antivirus can before file gets read using .net? What is the best way to do that?

    Wednesday, May 20, 2020 12:55 AM

All replies

  • Here's excellent article about writing an antivirus application. The information you need for monitoring read is at the "File System" section.

    Since drivers need to run inside the kernel space, generally you'll need to write in something like C.

    Wednesday, May 20, 2020 1:17 AM
    Answerer
  • Dont we have any third party api which can be used
    Wednesday, May 20, 2020 2:25 AM
  • Hi Prajakta,

    Thank you for posting here.

    Maybe you can try this one: AntiVirusScanner.

    Windows OS provide the common API to calling the anti virus software which is installed (Of course, the anti virus software required support the API). But, the API to calling the anti virus software provide only COM Interface style, not supported IDispatch. So, calling this API is too difficult from any .NET language and script language.

                var scanner = new AntiVirus.Scanner();
                var result = scanner.ScanAndClean(@"");
                Console.WriteLine(result);

    The result is an enum.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, May 20, 2020 5:43 AM
  • Much like the reason "why it's bad idea to write browser helper objects in .NET Framework?", the drivers in kernel have shared memory space, which means only one version of .NET Framework runtime can present at there.
    Wednesday, May 20, 2020 5:44 AM
    Answerer
  • Are you asking how to write an AV program or simply ensure it has run before you try to read a file in .NET?

    If you simply want to ensure it has run before you read a file then it is easy. AV works by monitoring access to the file system. Ensure whatever file you want to read is dropped onto a location that AV is monitoring and it'll scan it before you read it. If the file is bad then it'll block access so your app won't be able to read it. 

    This is a very common approach when working with web servers that support file uploads. We upload a file from the user and drop it onto a temp directory that AV is monitoring. AV scans the file automatically, the app doesn't need to do anything. When we attempt to read the file it'll either succeed or fail. If it fails we know the AV had a problem with the file.


    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, May 20, 2020 1:55 PM
    Moderator