1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2010 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * A helper class for invoking CreateProcess(). The lpProcessInformation
23 * can point to an uninitialized struct - it's memset to all zeroes inside.
26 class CCreateProcessHelper
29 static bool CreateProcess(LPCTSTR lpApplicationName
,
31 LPCTSTR lpCurrentDirectory
,
32 LPPROCESS_INFORMATION lpProcessInformation
);
33 static bool CreateProcess(LPCTSTR lpApplicationName
,
35 LPPROCESS_INFORMATION lpProcessInformation
);
37 static bool CreateProcessDetached(LPCTSTR lpApplicationName
,
39 LPCTSTR lpCurrentDirectory
);
40 static bool CreateProcessDetached(LPCTSTR lpApplicationName
,
41 LPTSTR lpCommandLine
);
44 inline bool CCreateProcessHelper::CreateProcess(LPCTSTR applicationName
,
45 LPTSTR commandLine
, LPCTSTR currentDirectory
,
46 LPPROCESS_INFORMATION processInfo
)
48 STARTUPINFO startupInfo
;
49 memset(&startupInfo
, 0, sizeof(STARTUPINFO
));
50 startupInfo
.cb
= sizeof(STARTUPINFO
);
52 memset(processInfo
, 0, sizeof(PROCESS_INFORMATION
));
53 const BOOL result
= ::CreateProcess( applicationName
,
54 commandLine
, NULL
, NULL
, FALSE
, 0, 0, currentDirectory
,
55 &startupInfo
, processInfo
);
59 inline bool CCreateProcessHelper::CreateProcess(LPCTSTR applicationName
,
60 LPTSTR commandLine
, LPPROCESS_INFORMATION processInformation
)
62 return CreateProcess( applicationName
, commandLine
, 0, processInformation
);
65 inline bool CCreateProcessHelper::CreateProcessDetached(LPCTSTR lpApplicationName
,
66 LPTSTR lpCommandLine
, LPCTSTR lpCurrentDirectory
)
68 PROCESS_INFORMATION process
;
69 if (!CreateProcess(lpApplicationName
, lpCommandLine
, lpCurrentDirectory
, &process
))
72 CloseHandle(process
.hThread
);
73 CloseHandle(process
.hProcess
);
77 inline bool CCreateProcessHelper::CreateProcessDetached(LPCTSTR lpApplicationName
,
80 return CreateProcessDetached(lpApplicationName
, lpCommandLine
, 0);