Share via


Antivirus Sample Application

Topic Last Modified: 2007-06-18

This sample agent responds to the OnEndOfData and OnSubmittedMessage events and sends the incoming message to an out of process Component Object Model (COM) server that asynchronously examines the message and returns a modified version of the message.

Structure of the Sample

The Antivirus sample agent consists of a Microsoft Visual Studio .NET 2005 C++ project and a simple Microsoft Visual Studio .NET 2005 C# project. By default, the files are installed in the directory in which the Microsoft Exchange Server 2007 Software Development Kit (SDK) is installed, in the \Samples\Antivirus\ folder.

The following are the primary files for the sample:

  • Install.ps1   An Exchange Management Shell script that installs the compiled sample.
  • Install-x64.ps1   An Exchange Management Shell script that installs the compiled sample in a 64-bit environment.
  • Uninstall.ps1    An Exchange Management Shell script that uninstalls the compiled sample.
  • Uninstall-x64.ps1    An Exchange Management Shell script that uninstalls the compiled sample in a 64-bit environment.
  • AntivirusAgent.csproj   The Visual Studio C# project file for the agent.
  • AntivirusService.vcproj   The Visual Studio C++ project file for the service.
  • HubAntivirusAgent.cs   The C# source code that contains the class that derives from the RoutingAgent class.
  • EdgeAntivirusAgent.cs   The C# source code that contains the class that derives from the SmtpReceiveAgent class.
  • ComStream.cs    The C# source code that implements the Component Object Model (COM) IStream interface over a .NET stream.
  • DotNetStream.cs    The C# source code that implements a .NET stream over a Component Object Model (COM) IStream.

Building the Sample

To build the Antivirus sample agent, you must first install Visual Studio .NET 2005 and the Microsoft .NET Framework version 2.0 on the computer that is running Exchange 2007 that has the Hub Transport server role installed.

After you install the required software, open theAntivirusService.vcproj C++ project by using Visual Studio .NET. Build the project and fix any errors you encounter. This will build AntivirusService.exe and ComInterop.dll.

After you build the antivirus service, open the AntivirusAgent.csproj C# project by using Visual Studio .NET. If it is necessary, update the references to the Microsoft.Exchange.Data.* namespaces. Build the project and fix any errors you encounter.

Installing the Sample

To install the Antivirus sample agent

  1. Edit the install.ps1 script to make sure that the $EXDIR variable is correctly initialized for your system. The value of the $EXDIR variable should be the path of the Microsoft Exchange Server 2007 installation directory.

  2. Open the Exchange Management Shell and run the install.ps1 script.

  3. Exit the Exchange Management Shell.

Uninstalling the Sample

To uninstall the Antivirus sample agent

  1. Edit the uninstall.ps1 script to make sure that the $EXDIR variable is correctly initialized for your system. The value of the $EXDIR variable should be the path of the Exchange Server 2007 installation directory.

  2. Open the Exchange Management Shell and run the uninstall.ps1 script.