UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / src / win32 / background.c
blobcc27745f26e85f92e16aa37a7f9567445af20f62
1 #include "windows.h"
3 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
4 PSTR szCmdLine, int iCmdShow)
6 PROCESS_INFORMATION procinfo;
7 STARTUPINFOA startinfo;
8 BOOL rc;
10 if (*szCmdLine == '\0')
12 MessageBox(NULL, "Usage: background.exe <command>", "Invalid usage!", MB_ICONSTOP);
13 return 1;
16 /* Init the STARTUPINFOA struct. */
17 memset(&startinfo, 0, sizeof(startinfo));
18 startinfo.cb = sizeof(startinfo);
20 rc = CreateProcess(NULL,
21 szCmdLine, // command line
22 NULL, // process security attributes
23 NULL, // primary thread security attributes
24 TRUE, // handles are inherited
25 DETACHED_PROCESS, // creation flags
26 NULL, // use parent's environment
27 NULL, // use parent's current directory
28 &startinfo, // STARTUPINFO pointer
29 &procinfo); // receives PROCESS_INFORMATION
30 if (!rc)
32 MessageBox(NULL, szCmdLine, "Failed to launch command!", MB_ICONSTOP);
33 return 1;
36 // Cleanup handles
37 CloseHandle(procinfo.hProcess);
38 CloseHandle(procinfo.hThread);
40 ExitProcess(0);