'VSCode C++ Compiled exe was infected with Win32:TrojanX-gen[Trj]

I am setting up VSCode for C++, made some simple code (test.cpp) to test if things are working.

  #include <iostream>

using namespace std;

int main(){
    cout << "Hello";
}

When I click run code the console says "Access is denied" and my antivirus pops up and says the test.exe and tempCodeRunnerFile.exe was infected with Win32:TrojanX-gen[Trj].

What exactly is Win32:TrojanX-gen[Trj] and how do I grant access so my antivirus wont pop up?



Solution 1:[1]

I had this issue as well. Its simply because some antiviruses think that unsigned .exe files (which is the output of your CPP file after you compile) are some sort of malicious file. You do need to exclude this from your antivirus, and your best bet is to first find out which antivirus you have, and second go to the "exclusions" list and add either the folder you're working with, or the file itself. I'm assuming you have AVG lol Exclusions can be found in the settings of your antivirus. Right click on the icon and see if you can go to preferences or settings. Then look for exclusions, or even an advanced setting option, and keep looking for something along the exclusions nature.

Solution 2:[2]

Just add an exception to the folder which contains your c++ code. (The whole folder). It did the job for mine ^-^

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Z41N
Solution 2 Arefin Anwar