Calling Sav32Cli.exe from asp.net c# application "Code 2 - If some error preventing further execution is discover "

552 views Asked by At

I have integrated Sav32Cli.exe in my asp.net c# application & its working fine in my local machine but when we move it on the testing server I am getting the following error "Code 2 - If some error preventing further execution is discover "

The scenario is If only 1 person performs the activity it works fine but concurrent connection performs the same activity then I am getting this error for some connections.

Actual scenario : We have the page where users upload the pdf file & as soon as the file is uploaded on the server we perform the scanning via sop-hos and when multiple users perform the same activity I am getting the following error : Code 2 - If some error preventing further execution is discover. So I would like to know from you guys what should I do to bypass this error & implement the scanning successfully into my application.

Below is the code I have written to integrate the scanning into my application :

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
try
{
    string filePath = sFileDetails.DirectoryName + "\\" + sFileName;
    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    startInfo.FileName = "C:\\Program Files (x86)\\Sophos\\Sophos Anti-Virus\\sav32cli.exe";
    startInfo.Arguments = String.Format(@" -ss ""{0}""", filePath); 
    process.StartInfo = startInfo;
    process.StartInfo.Verb = "runas";
    process.StartInfo.RedirectStandardOutput = true;
    process.StartInfo.UseShellExecute = false;
    process.Start();
    string output = process.StandardOutput.ReadToEnd();
    StringBuilder objStrBuilder = new StringBuilder();
    objStrBuilder.AppendLine("Status  " + output.ToString());
    int i = process.ExitCode;
    objStrBuilder.AppendLine("Code " + i.ToString());
    File.WriteAllText(sFileDetails.DirectoryName + "\\" + Convert.ToString(System.Guid.NewGuid()) + ".txt", Convert.ToString(objStrBuilder));
    if (i > 0)
    {
        return false;
    }
    return true;
}
catch (Exception ex)
{
    return false;
}
finally
{
    process.Close();
    process.Dispose();
}
2

There are 2 answers

0
Rahul Jain On BEST ANSWER

Sav32Cli.exe requires more permission to execute in web app. So impersonation technique helped me to solve this issue.

This link helped me to solve this issue : Click Here

0
HelpingHand On

Have you considered using SAVIDI for this - https://www.sophos.com/medialibrary/PDFs/partners/sophossavdidsna.ashx

SAV32CLI will take long time to load all the virus data into memory, I would expect around 5 seconds. This is fine when you're scanning your hard disk but per file it would be rather slow. If you're launching multiple instances then it would be quite a memory drain also.

If your throughput needs improving, I would suggest looking at SAVIDI. In this scenario there is service which loads the virus data once at startup and you can then ask it to scan a file/directory.

This post and attachment in the thread could help you: https://community.sophos.com/products/endpoint-security-control/f/sophos-endpoint-software/9420/sophos-sav-di-icap-code-sample

Regards.