-2

I created a program in c++ when i build it using VS C++ 2012 using release mode with

Runtime Library: "MultiThreaded(/MT)

Then its captured by avast antivirus as virus. But if i change Runtime Library to "MultiThreaded DLL(/MD)" then avast don't capture it as virus.

Here is code

LPWSTR _GetUserName();
void FileWriteLine(LPCWSTR filePath,LPCWSTR line);

int main()
{
    LPCWSTR userName = _GetUserName();
    FileWriteLine(userName,L"Hello World");
    return 1;
}


void FileWriteLine(LPCWSTR filePath,LPCWSTR line)
{
    wfstream fileHandle(filePath,ios::out | ios::app);
    fileHandle << line<<endl;
    fileHandle.close();
}

LPWSTR _GetUserName()
{
    LPWSTR username = new TCHAR[257];
    DWORD size = 257;

    if (!GetUserNameW(username,&size))
    {
        username = _wgetenv(L"USERNAME");
        if (username == NULL)
        {
            username = L"Error-Unknown";
        }
    }
    return username;
}
Talon
  • 43
  • 1
  • 12
  • 1
    Switch to a better antivirus software? Also, `_GetUserName` is a reserved identifier. – T.C. Oct 05 '14 at 10:30
  • Are you sure just the runtime makes your program be detected as a virus? It seems utterly strange – Marco A. Oct 05 '14 at 10:33
  • Can you upload your "virus" to https://www.virustotal.com/ and post the report url here? – wimh Oct 05 '14 at 12:43
  • i uploaded it on virustotal.com and its clear no virus. Avast capture it as virus only when it run. – Talon Oct 11 '14 at 05:15

2 Answers2

0

Go into the antivirus menu and set the folder where the executable is being created as an exception in the firewall.

Settings > Antivirus > scroll down to Exclusions > File path exclusions > Either type in the path and add it or browse to it then add it

Yann
  • 978
  • 2
  • 12
  • 31
0

It looks like you're not alone. http://blog.nirsoft.net/2009/05/17/antivirus-companies-cause-a-big-headache-to-small-developers/

http://social.msdn.microsoft.com/Forums/vstudio/en-US/f0e33f0b-fa4c-46bf-b515-186eb4d32660/code-gets-detected-as-a-virus

Stub each call that you make, and determine which API call is the problem, then replace it with something else. - Unless it's just the sheer fact of the compiler switch that causes the problem. Divide and conquer. Also submit the information to Avast.

GilesDMiddleton
  • 2,279
  • 22
  • 31