Why is Windows blocking my compiled C++ program?

August 9, 2026 3 answers
Asked by MellowPine42
I can compile my C++ source with g++ and produce main.exe, but running it from PowerShell sometimes fails with an error saying that an Application Control policy blocked the file. I already tried excluding the project folder from Windows Defender, but the executable is still blocked. What should I check or change?

Answers

SilverMango18
Make sure the build step succeeds before trying to run the program. In PowerShell, use `g++ main.cpp -o main.exe` and then run it with `./main.exe`. If compilation fails or produces the executable in another directory, PowerShell may be launching an older file. However, when the error specifically says an Application Control policy blocked the file, the main issue is Windows policyโ€”not the C++ code.
Reply to this answer
QuietOrbit53
The intermittent behavior can happen when the security tool evaluates newly created executables differently from previously trusted files. Avoid repeatedly disabling protection or downloading random replacement executables. Check the protection history and application-control logs, update the compiler from a trusted source, and ask the device administrator to whitelist the compiler/output if the machine is managed.
Reply to this answer
CrispHarbor7
This message usually comes from Windows Application Control rather than ordinary antivirus scanning. A Defender folder exclusion may not override an AppLocker, Smart App Control, or organization-managed policy. Check Windows Security and Event Viewer for the exact rule that blocked main.exe. If this is a school or work computer, an administrator may need to approve the compiler output or adjust the policy. On a personal computer, verify that the executable is really the one you just built and test from a normal local folder rather than a protected or synchronized directory.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions