When I compile my C++ file with g++ and try to run the resulting executable from PowerShell, I sometimes receive an error saying that an Application Control policy blocked main.exe. I already tried excluding the folder from Windows Defender, but the executable is still blocked. What should I check or change to fix this?
2 Answers
Make sure the compile command actually succeeds before launching the program. In PowerShell, use `g++ main.cpp -o main.exe`, then run it with `./main.exe` (or `.main.exe` in Windows PowerShell). If it works sometimes and fails other times, that points more toward an intermittent security scan or application-control rule than a problem in the source code.
This is not a C++ code error—the compiler is producing an executable, but Windows is preventing that executable from running. Check Windows Security's Protection History and the organization's application-control settings to see which policy blocked it. If this is a school or work computer, the restriction may be enforced by an administrator, so only they can approve the compiler output or change the policy. Avoid disabling security features just to run the file.

The code itself is unlikely to cause this message. If compilation finishes but execution is blocked, try building in a normal user-owned development folder and check the security event or protection history for the exact rule responsible.