How to virus scan an EXE file in C# .NET Framework

Everybody knows that sketchy EXE files are an excellent way to jeopardize your security. They also know that setting up virus scanning from within an app can be really painful. Don’t you worry, though, we have a nice easy solution for you today. Let’s dive straight in.

First off, we need to install our API client. Open up the console of package manager and paste in this command to get the installation started:

Install-Package Cloudmersive.APIClient.NET.VirusScan -Version 2.0.3

Alright, now we can call our API function and scan our file for viruses. This snippet will get things going:

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.VirusScan.Api;using Cloudmersive.APIClient.NET.VirusScan.Client;using Cloudmersive.APIClient.NET.VirusScan.Model;namespace Example{public class ScanFileExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new ScanApi();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.try{// Scan a file for virusesVirusScanResult result = apiInstance.ScanFile(inputFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ScanApi.ScanFile: " + e.Message );}}}}

Ok, that’s a wrap. Seriously, it’s just that easy.

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store