1 #include "windows.h"
2
WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)3 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
4 PSTR szCmdLine, int iCmdShow)
5 {
6 PROCESS_INFORMATION procinfo;
7 STARTUPINFOA startinfo;
8 BOOL rc;
9
10 if (*szCmdLine == '\0')
11 {
12 MessageBox(NULL, "Usage: background.exe <command>", "Invalid usage!", MB_ICONSTOP);
13 return 1;
14 }
15
16 /* Init the STARTUPINFOA struct. */
17 memset(&startinfo, 0, sizeof(startinfo));
18 startinfo.cb = sizeof(startinfo);
19
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)
31 {
32 MessageBox(NULL, szCmdLine, "Failed to launch command!", MB_ICONSTOP);
33 return 1;
34 }
35
36 // Cleanup handles
37 CloseHandle(procinfo.hProcess);
38 CloseHandle(procinfo.hThread);
39
40 ExitProcess(0);
41 }
42