zackychan97
zackychan97

Reputation: 146

How come my code causes my antivirus software to prevent it from running the executable?

I have a C# .NET 4.8 project that will cause my antivirus software to prevent it from running the executable file for the project. Here is the error it throws in Visual Studio:

enter image description here

And here is the notification my antivirus software appears to give me:

enter image description here

I have narrowed down the code that is causing this... In summary, I am using a timer that will run every minute, and on its tick event (when the timer is up) it will do a check to look for a file name (I call this file "Terminate"), if there is this file it will close the program after 3 minutes.

The end users are all on a virtual environment on the same network and are all running this program from the same directory. Thus, if there is any maintenance that needs to be performed on these virtual environments, I can manually change the file name from "xTerminate" to "Terminate" and the programs will close in all of those environments without having to get users to do it manually.

public Timer poisonPill = new Timer();
poisonPill.Interval = (1 * 60 * 1000);  // every 1 minutes
poisonPill.Tick += new EventHandler(poisonPill_Tick);
poisonPill.Start();

When this 1-minute timer reaches the interval time-length, it runs this event:

private void poisonPill_Tick(object sender, EventArgs e)
    {
        if (File.Exists("Terminate.txt"))
        {
            poisonPill.Enabled = false;

            string message;

            try
            {   // Open the text file using a stream reader.
                using (StreamReader sr = new StreamReader("Terminate.txt"))
                {
                    // Read the stream to a string
                    String line = sr.ReadToEnd();
                    message = line;
                }
            }
            catch (Exception ex)
            {
                message = "Application closing in 3 minutes for maintenance by administrator";
            }

            Timer terminator = new Timer();
            terminator.Interval = (3 * 60 * 1000);
            terminator.Tick += terminator_Tick;
            terminator.Start();

            MessageBox.Show(message + "\n\nNotification Time:  " + DateTime.Now.ToString("h:mm tt") +
                "\n\nApplication closes 3 minutes after Notification Time.", "3-Minute Application Closing Alert");
        }
    }

And then once that 3-minute timer finishes...:

private void terminator_Tick(object sender, EventArgs e)
    {
        Application.Exit();
    }

Upvotes: 0

Views: 1657

Answers (1)

Robert Szabo
Robert Szabo

Reputation: 71

Anti-Virus software does that often because it's a new executable with weird behavior that it's not used to. It doesn't recognize it like an official app like Steam or Discord. It does it with pirated games, too. But it's nothing to worry about, you made the app, you know what it was made to do. The antivirus doesn't know, and it's just defending. I usually just turn off my antivirus temporarily, or add an exception so it won't turn my app off when I'm testing. You can add an exception in the antivirus settings, depending on what antivirus you use, there must be a place where you can select the exe location, and the antivirus will ignore it.

Upvotes: 3

Related Questions