text: #include <stdio.h>
  #include <string.h>
  #include <windows.h>
  
  #define BUFFER_SIZE 1024
  
  int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  {
    char tempPath[BUFFER_SIZE];
    char exePath[BUFFER_SIZE];
    char batPath[BUFFER_SIZE];
    char batPathWithArgs[BUFFER_SIZE * 2];
    char comSpec[BUFFER_SIZE];
    char *commandLine;
    FILE *fpExe, *fpBat;
    int batFileSize, result = 0, i, quoted;
    DWORD exitCode = 0;
    PROCESS_INFORMATION pi;
    STARTUPINFO si;
  
    GetTempPath(BUFFER_SIZE, tempPath);
    GetModuleFileName(NULL, exePath, BUFFER_SIZE);
    GetEnvironmentVariable("comspec", comSpec, BUFFER_SIZE);
  
    fpExe = fopen(exePath, "r");
    if (!fpExe) {
      MessageBox(NULL, "0001:Can't access batfile data.", "error", MB_OK);
      return 1;
    }
    result |= fseek(fpExe, -4, SEEK_END);
    result |= fread(&batFileSize, 4, 1, fpExe) <= 0;
    result |= fseek(fpExe, -(batFileSize+4), SEEK_END);
    if (result || batFileSize <= 0) {
      MessageBox(NULL, "0002:Can't read batfile header.", "error", MB_OK);
      return 1;
    }
  
    sprintf(strcpy(batPath, tempPath) + strlen(tempPath), "%d.bat", GetTickCount());
    fpBat = fopen(batPath, "w");
    if (!fpExe) {
      MessageBox(NULL, "0003:Can't create temp file.", "error", MB_OK);
      return 1;
    }
    for (i = 0; i < batFileSize; ++i) fputc(fgetc(fpExe)^0xff, fpBat);
    if (ferror(fpExe)) {
      MessageBox(NULL, "0004:Can't read batfile data.", "error", MB_OK);
      return 1;
    }
    if (ferror(fpBat)) {
      MessageBox(NULL, "0005:Can't write temp file.", "error", MB_OK);
      return 1;
    }
  
    fclose(fpExe);
    fclose(fpBat);
  
    commandLine = GetCommandLine();
    quoted = *commandLine == '"';
    while (*commandLine == ' ' || *commandLine == '"') ++commandLine;
    if (quoted) commandLine = strchr(commandLine+1, '"');
    else        commandLine = strchr(commandLine, ' ');
    if (!commandLine) commandLine = "";
    while (*commandLine == '"') ++commandLine;
    while (*commandLine == ' ') ++commandLine;
    sprintf(batPathWithArgs, "/c \"\"%s\" %s\"", batPath, commandLine);
    ZeroMemory(&si, sizeof(STARTUPINFO));
    si.cb = sizeof(STARTUPINFO);
    if (!CreateProcess(comSpec, batPathWithArgs, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi )) {
      MessageBox(NULL, "0006:Can't create bat process.", "error", MB_OK);
      return 1;
    }
    if (WAIT_OBJECT_0 == WaitForSingleObject(pi.hProcess, INFINITE)) GetExitCodeProcess(pi.hProcess, &exitCode);
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);
    remove(batPath);
  
    return exitCode;
  }
  