title: Delphi programs blocked by antivirus programs
body: <p>I have a piece of code that is trying to write to disk many files in one second. However, it fails wince I have installed Kaspersky Anrivirus 2011. </p>
  
  <pre><code>Stream:= TFileStream.Create(sName, fmCreate); 
  </code></pre>
  
  <p>The code totally worked with Kaspersky 2010 and also works with Kaspersky 2011 if I disable its scanners (it cannot be totally unloaded from memory - unless it is uninstalled). The code also works if (Kaspersky 2011 is running and) I write to disk slooooowly. So it obviously is not fast enough to handle my disk requests.</p>
  
  <p>The error I get is EFCreateError ('Cannot create xxx file blablabla'). Error is random. Most of the files are written to disk. About 10% fail.</p>
  
  <p>I have tried to get support but is impossible to find a real person at Kaspersky to speak with. Their so called 'support' is actually a FAQ data base. Of course it speaks about how to install the product and related stuff. There is nothing about programing-related issues. Any ideas?</p>
  
  <p>PS: this has repercussions for the entire Delphi community! All our customers will fail to use Delphi software if they are using KIS 2011 as antivirus. For the moment I recommend to my users to disable their antivirus but I need a real solution. </p>
  
  <p>It will be nice if a person with KIS 2011 can confirm the problem. Just create a tiny program that write 200 small files to disk using TFileStream.</p>
  
  <p><strong>UPDATE:</strong>  </p>
  
  <ul>
  <li>The problem appears ONLY when the file does not exist and it is created (created as opposed to overwritten).</li>
  <li>Similar report: <a href="https://forums.embarcadero.com/thread.jspa?threadID=32751&amp;tstart=15" rel="nofollow noreferrer">https://forums.embarcadero.com/thread.jspa?threadID=32751&amp;tstart=15</a></li>
  <li>Similar report: <a href="http://forum.kaspersky.com/index.php?showtopic=120561" rel="nofollow noreferrer">http://forum.kaspersky.com/index.php?showtopic=120561</a></li>
  <li>A possible solution that popped in my mind is to detect if KIS is running and if it is, to put a delay after each writing to disk. Or at leat, let the user know there may be problems. Anybody knows how to detect if a service is running?</li>
  <li>I added a delay of 650ms (after each file creation) and the bug is still there). So is not about how fast you write to disk but about how many files you write.</li>
  <li>Just uninstalled KIS 2011. The problem does not appear anymore.</li>
  <li>Just reinstalled the good old KIS 2010. The bug is still there but it appear rarely (about every 300 files instead of about 30 as in KIS 2011).</li>
  <li>The problem was confirmed on a second computer.</li>
  <li>NEWS: The crash appears in TFileStream.Create however it may be caused by a function called earlier: TestWriteAccess. If I disable this function, the TFileStream.Create doesn't fail anymore. Well, this doesn't change things too much. No matter which line of code generates the error, the program still fails (randomly) to write files to disk while Kaspersky is running. </li>
  <li>Still waiting a response from a <em>real person</em> from Kaspersky...</li>
  <li>More automated responses received from Kaspersky support (I sent emails to support in several countries). All pointing to a FAQ database.</li>
  <li>I change my status from Kaspersky fan (and customer) to Kaspersky hater because I finally receive an answer from a real person from Kaspersky support and it was plain and simple obnoxious. </li>
  </ul>
  
  <p>To test the code, try to use the code in a loop, to create 1000 files. The program creates a bunch of files (random number) then it fails at StreamFile:= TFileStream.Create.
  Update: The issue can be fixed by entering a small delay after creating each file.<br>
  <a href="https://docs.google.com/forms/d/1H3_O1z1iEqfh9ZT9u3B0R1tGEj-Hc9o7rAE0LKPr33Y" rel="nofollow noreferrer">https://docs.google.com/forms/d/1H3_O1z1iEqfh9ZT9u3B0R1tGEj-Hc9o7rAE0LKPr33Y</a>  </p>
  
  <p><strong>2013 Update</strong></p>
  
  <p>Starting with this afternoon (after an update) KIS conflicts with Delphi.
  Every time I compile a project KIS spikes to 100% CPU utilization. I will have to uninstall it.</p>
  
  <p><strong>2017 Update</strong></p>
  
  <p>All false positive alarms disappeared magically for all my Delphi programs starting with 2017. It seems that it was enough for a program like Kaspersky remove Delphi-generated executables from its virus list; all other smaller antivirus programs followed. </p>
  
  <hr>
  
  <p>Delphi 7, Win 7 (32), KIS 2011</p>