bd14d4d4163e9f15cc1d4ba48256c67f7ae6ac2d
[idea/community.git] / native / VistaUpdaterLauncher / VistaUpdaterLauncher / VistaUpdaterLauncher.cpp
1 // VistaUpdaterLauncher.cpp : Defines the entry point for the console application.
2 //
3
4 #include "stdafx.h"
5 #include <windows.h>
6 #include <process.h>
7 #include <stdio.h>
8 #include <tchar.h>
9 #include <conio.h>
10 #include <string.h>
11 #include <stdlib.h>
12
13
14 int _tmain(int argc, _TCHAR* argv[])
15 {
16         STARTUPINFO startupInfo = {0};
17         startupInfo.cb = sizeof(startupInfo);
18         PROCESS_INFORMATION processInformation = {0};
19
20         startupInfo.hStdInput  = GetStdHandle(STD_INPUT_HANDLE);
21         startupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
22         startupInfo.hStdError  = GetStdHandle(STD_ERROR_HANDLE);
23
24         wchar_t commandLine[32768] = L"";
25
26         for (int i = 1; i < argc; i++) {
27         wcscat_s(commandLine, L"\"");
28         wcscat_s(commandLine, argv[i]);
29         wcscat_s(commandLine, L"\" ");
30         }
31
32         wprintf(L"Creating new process: %s\n", commandLine);
33         fflush(stdout);
34
35         if (!CreateProcess(
36                 NULL, /*LPCTSTR lpApplicationName*/
37                 commandLine,/* LPTSTR lpCommandLine*/
38                 NULL, /*LPSECURITY_ATTRIBUTES lpProcessAttributes*/
39                 NULL, /*LPSECURITY_ATTRIBUTES lpThreadAttributes*/
40                 TRUE, /*BOOL bInheritHandles,*/
41                 0,    /*DWORD dwCreationFlags*/
42                 NULL, /*LPVOID lpEnvironment*/
43                 NULL, /*LPCTSTR lpCurrentDirectory*/
44                 &startupInfo, /*LPSTARTUPINFO lpStartupInfo*/
45                 &processInformation /*LPPROCESS_INFORMATION lpProcessInformation*/))
46         {
47                         wprintf(L"Cannot create process: %d\n", GetLastError());
48                         return -1;
49         }
50
51         WaitForSingleObject(processInformation.hProcess, INFINITE);
52
53         DWORD exitCode = 0;
54         if (!GetExitCodeProcess(processInformation.hProcess, &exitCode))
55         {
56                 wprintf(L"Cannot retrieve process exit code: %d\n", GetLastError());
57                 exitCode = -1;
58         }
59         CloseHandle(processInformation.hProcess);
60
61         return exitCode;
62 }
63