Hallo!
Ich hab ein Win32 Consolen Programm geschrieben das als Scheduled Task laufen soll und, unter anderem, automatisch Zip files mit hilfe eines externen packprogramms erstellt.
Das ganze funktioniert, wenn ich das Programm auf der Console starte, wunderbar.
Jedoch wenn es als Scheduled Task startet bekomme ich beim CreateProcess eine Windows Fehlermeldung (Messagebox) mit folgender Fehlermeldung:
"The Application failed to initzialize properly.
Click OK to terminate the aplication."
Ich hab im Moment leider keine Ahnung woran es liegen könnte und hoffe das jemand von euch rat weiß!
Wäre für jeden Rat dankbar!
Code zum Zippen:
PHP-Code:
/*** Function CompressFile ***\
exepath Path of the zip executable
source source directory where the file to be compressed lies
dest destination path where compressed file will be put
name source filename
password password for encryption
returns 999 if the process could not be created or the returncode of the zip programm
*/
#define ZIP_COMPRESS_FORMAT "%s -add -lev=9 -silent -move -pass=%s \"%s%s.zip\" \"%s%s\""
#define ZIP_COMPRESS_FORMAT_LEN 56
int CompressFile(char *exepath,char * source, char *dest, char *name, char *password)
{
STARTUPINFO sti;
PROCESS_INFORMATION pri;
char *cmdline;
DWORD exitcode;
//Assemble Commandline
cmdline=(char*)malloc(sizeof(char)*(ZIP_COMPRESS_FORMAT_LEN+1+strlen(exepath)+strlen(source)+strlen(dest)+strlen(password)+strlen(name)*2));
sprintf(cmdline,ZIP_COMPRESS_FORMAT,exepath,password,dest,name,source,name);
memset(&sti,0,sizeof(STARTUPINFO));
sti.cb=sizeof(STARTUPINFO);
sti.lpDesktop="";
if (CreateProcess(NULL, cmdline,NULL, NULL, 0, NORMAL_PRIORITY_CLASS, NULL, NULL, &sti, &pri))
{
//Wait till process has finished
WaitForSingleObject( pri.hProcess, INFINITE );
//And save the exitcode to be returned
GetExitCodeProcess(pri.hProcess, &exitcode);
//Cleanup
CloseHandle( pri.hProcess );
CloseHandle( pri.hThread );
free(cmdline);
return exitcode;
}
else
{
//The process could not be created
free(cmdline);
return 999;
}
}
LG