copyrights in native sources
[idea/community.git] / native / VistaUpdaterLauncher / VistaUpdaterLauncher / VistaUpdaterLauncher.cpp
1 /*
2  * Copyright 2000-2009 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "stdafx.h"
18 #include <windows.h>
19 #include <process.h>
20 #include <stdio.h>
21 #include <tchar.h>
22 #include <conio.h>
23 #include <string.h>
24 #include <stdlib.h>
25
26
27 int _tmain(int argc, _TCHAR* argv[])
28 {
29         STARTUPINFO startupInfo = {0};
30         startupInfo.cb = sizeof(startupInfo);
31         PROCESS_INFORMATION processInformation = {0};
32
33         startupInfo.hStdInput  = GetStdHandle(STD_INPUT_HANDLE);
34         startupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
35         startupInfo.hStdError  = GetStdHandle(STD_ERROR_HANDLE);
36
37         wchar_t commandLine[32768] = L"";
38
39         for (int i = 1; i < argc; i++) {
40         wcscat_s(commandLine, L"\"");
41         wcscat_s(commandLine, argv[i]);
42         wcscat_s(commandLine, L"\" ");
43         }
44
45         wprintf(L"Creating new process: %s\n", commandLine);
46         fflush(stdout);
47
48         if (!CreateProcess(
49                 NULL, /*LPCTSTR lpApplicationName*/
50                 commandLine,/* LPTSTR lpCommandLine*/
51                 NULL, /*LPSECURITY_ATTRIBUTES lpProcessAttributes*/
52                 NULL, /*LPSECURITY_ATTRIBUTES lpThreadAttributes*/
53                 TRUE, /*BOOL bInheritHandles,*/
54                 0,    /*DWORD dwCreationFlags*/
55                 NULL, /*LPVOID lpEnvironment*/
56                 NULL, /*LPCTSTR lpCurrentDirectory*/
57                 &startupInfo, /*LPSTARTUPINFO lpStartupInfo*/
58                 &processInformation /*LPPROCESS_INFORMATION lpProcessInformation*/))
59         {
60                         wprintf(L"Cannot create process: %d\n", GetLastError());
61                         return -1;
62         }
63
64         WaitForSingleObject(processInformation.hProcess, INFINITE);
65
66         DWORD exitCode = 0;
67         if (!GetExitCodeProcess(processInformation.hProcess, &exitCode))
68         {
69                 wprintf(L"Cannot retrieve process exit code: %d\n", GetLastError());
70                 exitCode = -1;
71         }
72         CloseHandle(processInformation.hProcess);
73
74         return exitCode;
75 }
76