Is it possible to reasonably bypass antivirus scanning of the working directory?

My Win32 application performs numerous disk operations in the designated temporary folder during operation, and a serious redesign is out of the question.

Some clients have antivirus software that scans the same temporary directory (it just scans everything). We tried to talk to them about turning it off - it wonโ€™t work, so itโ€™s out of the question.

From time to time (something like once for every thousand file operations), my application tries to perform an operation on a file that is opened by antivirus at that time and therefore is blocked by the operating system. An exchange violation occurs and causes an error in my application. This happens approximately every three minutes on average.

A temporary folder can contain up to 100 thousand files in most typical scenarios, so I do not like the idea of โ€‹โ€‹constantly opening them, because this can lead to exhaustion of resources in some boundary conditions.

Is there a reasonable strategy for my application to respond to situations where the required file is locked? Maybe something like this?

for( int i = 0; i < ReasonableNumber; i++ ) {
    try {
        performOperation(); // do useful stuff here
        break;
    } catch( ... ) {
        if( i == ReasonableNumber - 1 ) {
            throw; //not to hide errors if unlock never happens
        }
    }
    Sleep( ReasonableInterval );
 }

Is this a viable strategy? If so, how many times and how often should I repeat the application? What ideas are better if they are?

+3
source share
6 answers

I had experience working with antivirus software created by both Symantec and AVG, making the files unavailable for opening.

, 2002 Symantec, MSDev6, :

  • .
  • tmp +
  • tmp
  • tmp

5 6. Symantec -, , (CreateFile ERROR_DELETE_PENDING). MSDev6 , , 6 . 7 . . , !

AVG , .

/ โ€‹โ€‹ , . 5.

+1

, , . , , ...; -)

, . - , " ", . OTOH, , ? , ? : ( ) . 100 . virusscanner , , . , , . , ... โ†’ , , , .

.

+4

, , 10 100 Kb, , 5 100 (0,1 ). , , YMMV.

, , :

using System;

namespace Retry
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 0;
            Utils.Retry(() =>
            {
                i = i + 1;
                if (i < 3)
                    throw new ArgumentOutOfRangeException();
            });
            Console.WriteLine(i);
            Console.Write("Press any key...");
            Console.ReadKey();
        }
    }

    class Utils
    {
        public delegate void Retryable();
        static int RETRIES = 5;
        static int WAIT = 100; /*ms*/
        static public void Retry( Retryable retryable )
        {
            int retrys = RETRIES;
            int wait = WAIT;
            Exception err;
            do
            {
                try
                {
                    err = null;
                    retryable();
                }
                catch (Exception e)
                {
                    err = e;
                    if (retrys != 1)
                    {
                        System.Threading.Thread.Sleep(wait);
                        wait *= 2;
                    }
                }
            } while( --retrys > 0 && err != null );
            if (err != null)
                throw err;
        }
    }
}
+2

, ? , .

, , , , .

+1

. , , (, ).

, , , , .

, .

+1

, - - , - , .

Your solution, although perhaps not the most elegant, will certainly work as long as ReasonableNumberit is large enough - in the past I used 10 as a reasonable number. Of course, I would not go higher, and you could leave with a lower value, such as 5.

The meaning of sleep? 100 ms or 200 ms no more

Remember that in most cases your application will receive the file for the first time.

+1
source

Source: https://habr.com/ru/post/1709986/


All Articles