4

I'm using Visual Studio 2019 (Community Edition). I've never had an issue when compiling C++ code. I simply get the final executable and I'm able to run it without a problem. Recently I've decided to learn C and this is the C program that I'm compiling:

#include <stdio.h>

int main()
{
    printf("Hello, world! \n");

    return 0;
}

The file name is "main.c".

I haven't changed any of the default project settings and the project that I selected was "empty C/C++ project".

The code compiles fine but when I attempt to run the executable I get this error:

Unable to start program [path to .exe file]

Operation did not complete successfully because the file contains a virus or potentially unwanted software.

I can resolve this issue by going to Windows Defender and manually allowing this detected threat but obviously the issue with this approach is that other people won't be able to run my C programs without them being detected as a virus.

Ultimately, I believe this problem is related to how VS2019 is compiling my program rather than Windows Defender because I'm able to compile C++ (and other languages) into executables that run perfectly fine.

Hyden
  • 93
  • 1
  • 7
  • Read this then relocate to a remote forest and discard all computers https://www.win.tue.nl/~aeb/linux/hh/thompson/trust.html – NadavS Apr 02 '20 at 09:34
  • but seriously now, try disassembling your code and checking for fishy stuff, obviously this usually doesn't happen. – NadavS Apr 02 '20 at 09:36
  • Virus checkers use heuristics to spot patterns in executables that conform to known viruses. Just tell defender to ignore this program from scans. – Paul Ogilvie Apr 02 '20 at 09:44
  • @PaulOgilvie The issue with that approach, as stated in the question, is that (1) I would have to do that for every program I ever create using C and (2) everyone who wants to run my programs would be forced to do the same. It does not look very professional when software you're attempting to run on your computer is flagged as a virus by probably the most commonly used antivirus software. – Hyden Apr 02 '20 at 14:45
  • No you don't. The heuristic is specific to a pattern that most likely will not be present in your other programs. It has nothing to do with C or C++. Lookup the word "heuristic". – Paul Ogilvie Apr 03 '20 at 08:41
  • Did you find a satisfactory solution to this problem? I'm trying to teach C to a student who uses Windows, and have encountered this ridiculous issue. – Jivan Pal Apr 26 '20 at 00:55
  • @JivanPal just had the issue after updating Visual Studio 2019 which had me restart my computer. Closed Visual Studio & reopened and the project's working fine, no changes. weird bug honestly – artman41 Apr 27 '20 at 00:30
  • @artman41 My issue didn't actually concern Visual Studio, but the problematic behaviour was as described here. I'm writing C programs in VS Code and compiling using GCC (MinGW). I've now resolved the issue by whitelisting the project directory in Windows Defender, but had to go through some hoops to be able to do that on my student's Windows installation, as they have the Education edition, and there was some administrative restriction on the antivirus settings, despite there only being one user account on the machine. – Jivan Pal Apr 28 '20 at 04:35
  • In particular, I circumvented the odd administrative restriction I encountered in Defender by deleting some registry keys [as described here](https://www.tenforums.com/windows-updates-activation/43653-some-settings-managed-your-organisation-2.html). – Jivan Pal Apr 28 '20 at 04:37
  • maybe coz most bots are written in c :) and assembly – Dr Deo Apr 18 '21 at 02:51

0 Answers0