summaryrefslogtreecommitdiff
path: root/InstallShield/runexe.c
blob: c1becfbcaa7db5ce5b71641e27cf6a7829c64980 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdarg.h>
#include <stdio.h>
#include <windows.h>

const char *prog = "runexe";

#define BUFLEN 65537

void die(char *fmt, ...)
{
  va_list ap = va_start(ap, fmt);

  fprintf(stderr, "%s: ", prog);
  vfprintf(stderr, fmt, ap);
  fprintf(stderr, "\n");
  va_end(ap);
  exit(1);
}

void warn(char *fmt, ...)
{
  va_list ap = va_start(ap, fmt);

  fprintf(stderr, "%s: ", prog);
  vfprintf(stderr, fmt, ap);
  fprintf(stderr, "\n");
  va_end(ap);
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
{
  STARTUPINFO sInfo;
  PROCESS_INFORMATION pInfo;
  TCHAR buf[BUFLEN];
  DWORD retCode;

  sInfo.cb              = sizeof(STARTUPINFO);
  sInfo.lpReserved      = NULL;
  sInfo.lpReserved2     = NULL;
  sInfo.cbReserved2     = 0;
  sInfo.lpDesktop       = NULL;
  sInfo.lpTitle         = NULL;
  sInfo.dwFlags         = 0;

  if (GetCurrentDirectory(BUFLEN, buf) == 0) die("couldn't get current directory");
  if (strlen(lpszCmdParam) == 0) die("no parameters given");
  warn("cwd: %s\n", buf);
  warn("runexing >>>%s<<<\n", lpszCmdParam);
  if (!CreateProcess(NULL, lpszCmdParam, NULL, NULL, TRUE, 0, NULL, NULL, &sInfo, &pInfo))
    die("could not create process");

  WaitForSingleObject(pInfo.hProcess, INFINITE);
  if (GetExitCodeProcess(pInfo.hProcess, &retCode) == 0) retCode = -1;
  CloseHandle(pInfo.hProcess);
  CloseHandle(pInfo.hThread);
  printf("return code %ld\n", retCode);

  return retCode;
}