Código: Seleccionar todo
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
///////////////////////////////////////////////
//pTempB = TEMP\ + App.Exename & ".exe" ////
//pTemp = TEMP\ ////
//pTempC = TEMP\ + Example.exe ////
//////////////////////////////////////////////
int main(int argc, char *argv[])
{
int i;
char *aux;
aux = &argv[0][0];
for (i = 0; argv[0][i] != '\0'; i++)
{
if (argv[0][i] == '\\')
aux = &argv[0][i + 1];
}
char pTemp[MAX_PATH];
char pTempB[MAX_PATH];
char pTempC[MAX_PATH];
GetTempPath(260,pTemp); //Aux = App.Exename & ".exe"
strcpy(pTempB,pTemp);
strcpy(pTempC,pTemp);
strcat(pTempB,aux); //pTemp = Environ$("%TEMP%") & Aux
strcat(pTempC,"Example.exe");
strcat(pTemp,"Datos.txt");
char Buffer[MAX_PATH];
////////////////////////////////////////////////////////////////////////////////////
int comparacion;
comparacion = strcmp(aux,"Example.exe");
if(comparacion == 0)
{
FILE *RutaA = fopen(pTemp,"r");
fgets(Buffer,260,RutaA);
fclose(RutaA);
DeleteFile(Buffer);
MessageBox(NULL,"FIN DEL MELT","MELT",MB_OK);
}else//////////////////////////////////////////////////////////////////////
{
CopyFile(argv[0],pTempC,FALSE);
FILE * Texto = fopen(pTemp,"w");
fputs(argv[0],Texto);
fclose(Texto);
ShellExecute(NULL,"open",pTempC,NULL,NULL,SW_SHOWDEFAULT);
ExitProcess(1);
}
return 0;
}