Program when compiled with /MT antivirus capture it as virus

385 Views Asked by At

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;
}
2

There are 2 best solutions below

0
Yann On

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

0
GilesDMiddleton On

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.