4

I am compiling C++ code using Visual Studio 2019. The code ranges from simple projects to learn C++ features to game dev. But no matter the scope of the projects I get this message:

Security Scan Required Your administrator requires a security scan of this item. The scan could take up to 10 seconds.

This stalls the Visual C++ compiler and ultimately slows down my workflow. This occurs every time I try to compile my code. The weird thing is, on this same machine I've been compiling code without this problem. I am unsure of what caused this change and I want to revert it but don't know how.

AbdelRahman Mahmoud
  • 153
  • 1
  • 1
  • 12
  • 2
    did you ask your administrator? – 463035818_is_not_an_ai Sep 14 '20 at 13:31
  • 1
    To me it sounds like you're using a work or school computer which was not intended for using Visual Studio or development. This is really an issue with your organization, and not something any of us could do anything about. – Some programmer dude Sep 14 '20 at 13:33
  • @idclev463035818 This is my own personal machine and my user is the admin of the machine. I've been told that because this is an oem copy of Windows that I don't have all admin privilages. – AbdelRahman Mahmoud Sep 14 '20 at 13:35
  • @Someprogrammerdude As I said, this is my own personal machine and doesn't belong to any organization. – AbdelRahman Mahmoud Sep 14 '20 at 13:35
  • Then even if it's an OEM installation of Windows, you should have the rights to update the directories scanned by the anti-virus. There are many duplicates of this issue both here on Stack Overflow, as well as on other sites in the Stack Exchange network. Not to mention plenty of information all over the Internet. What have you searched for? What have you found? – Some programmer dude Sep 14 '20 at 13:39
  • @Someprogrammerdude I have specifically searched for a windows defender scan when compiling code using Visual Studio, the only solution I found was to turn off Controlled Folder Access but it is already turned off on my machine. – AbdelRahman Mahmoud Sep 14 '20 at 13:44
  • Searching for `windows defender interferes with visual studio build` gave me plenty of link to research. Some of them told me how to *exclude* both directories as well as Visual Studio specific processes from scanning. – Some programmer dude Sep 14 '20 at 13:49
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/221455/discussion-between-abdelrahman-mahmoud-and-some-programmer-dude). – AbdelRahman Mahmoud Sep 14 '20 at 14:12

5 Answers5

7

Go to

Start > Settings > Update & Security > Windows Security > Virus & threat protection 

Under Virus & threat protection settings, select Manage settings, and then under Exclusions, select Add or remove exclusions. Select Add an exclusion, and then select the file type .cpp from files, folders, file types, or process.

Add an exclusion to Windows Security

Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41
BadKitten
  • 71
  • 1
  • 5
5

The problem here occurs due to Windows Defender Real-Time Protection, which is very important to keep the system safe. The solution I found was based on these articles:

Microsoft description of the problem and simple fixes

How to create and run Windows Powershell scripts

Powershell script that excludes all the necessary directories and processes for Visual Studio 2019

The solution is to add Windows Defender Exclusions to all the processes and directories you use for your development environment, this gets rather complicated to do on your own and differs depending on your development environment of choice, here I am using Visual Studio 2019 and will use a Powershell script to quickly add these exclusions.

Simply download the Powershell script, open Windows Powershell, and type Set-ExecutionPolicy Unrestricted

Then navigate to the directory of the script. For simplicity, put the script in your root C: and navigate there then type ./{Script name} the "./" are important to run scripts from non-default directories.

The script will ask where you store your project folders, this is important to exclude from Windows Defender. After running the script you're pretty much done.

One final step, Set-ExecutionPolicy Restricted and then Get-ExecutionPolicy to verify it's restricted, it's very important not to overlook your Powershell Execution Policy as it's a very powerful attack vector.

I have done these exact steps and can verify that Windows Defender no longer stalls my code builds using Visual Studio 2019. This might mean that running an older or newer version of Visual Studio with a different directory structure would require another script, or Microsoft could step in and create a universal solution to exclude their own development environments form Windows Defender scans.

AbdelRahman Mahmoud
  • 153
  • 1
  • 1
  • 12
1

Okay, I also got this message when I was using CodeRunner Extension in VSCode. Every time I run the code with CodeRunner I was getting this Notification.

The solution that worked for me was simple:

  1. Go To Virus & Threath Protection.
  2. Turn Off these Two Options: Cloud-delivered protection, Automatic sample submission. Just like this:

enter image description here

0

The answer that OP has marked accepted worked. However, the script he mentioned has to be something written on it, so I created a new script (See the 2nd link mentioned in the above post for creating a script) and copied the code from Github https://gist.github.com/dknoodle/5a66b8b8a3f2243f4ca5c855b323cb7b and pasted in my script and run the command ./{Name of your script} in the Powershell. Be sure to open PowerShell in Administrator mode. Also if you are pasting your script in root C: and want to open your script then make sure that your command refers to the root folder of C: .You can type cd.. to come out of the directory.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31578334) – VainMan Apr 25 '22 at 06:55
0

Solved

Just had this same problem. To simplify.

Create a new folder that you save only c++ and supporting files to. I created one under Downloads/VSCode.

  1. Open the Windows start menu (Windows button)
  2. Type in Windows Security
  3. Select it.
  4. Click on 'Virus and threat protection' found in the left column
  5. Under 'Virus & threat protection settings' click: 'Manage settings'
  6. Scroll down to Exclusions
  7. Click on 'add or remove exclusions' then select + Add an exclusion
  8. Select 'folder' as type, then browse to your VSCode file folder you created (e.g., 'Downloads/VSCode') and select it.
  9. Restart VSCode, though probably not necessary, and the problem is resolved.