diff options
| author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2021-12-27 00:00:00 +0000 |
|---|---|---|
| committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-03-18 15:35:13 +0500 |
| commit | f19f813537c7aea1c20749c914e756b54a9c3cf5 (patch) | |
| tree | 816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /CPP/Windows/ProcessUtils.cpp | |
| parent | 98e06a519b63b81986abe76d28887f6984a7732b (diff) | |
| download | 7zip-f19f813537c7aea1c20749c914e756b54a9c3cf5.tar.gz 7zip-f19f813537c7aea1c20749c914e756b54a9c3cf5.tar.bz2 7zip-f19f813537c7aea1c20749c914e756b54a9c3cf5.zip | |
'21.07'21.07
Diffstat (limited to 'CPP/Windows/ProcessUtils.cpp')
| -rw-r--r-- | CPP/Windows/ProcessUtils.cpp | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/CPP/Windows/ProcessUtils.cpp b/CPP/Windows/ProcessUtils.cpp new file mode 100644 index 0000000..9bf0538 --- /dev/null +++ b/CPP/Windows/ProcessUtils.cpp | |||
| @@ -0,0 +1,102 @@ | |||
| 1 | // ProcessUtils.cpp | ||
| 2 | |||
| 3 | #include "StdAfx.h" | ||
| 4 | |||
| 5 | #include "../Common/StringConvert.h" | ||
| 6 | |||
| 7 | #include "ProcessUtils.h" | ||
| 8 | |||
| 9 | #ifndef _UNICODE | ||
| 10 | extern bool g_IsNT; | ||
| 11 | #endif | ||
| 12 | |||
| 13 | namespace NWindows { | ||
| 14 | |||
| 15 | #ifndef UNDER_CE | ||
| 16 | static UString GetQuotedString(const UString &s) | ||
| 17 | { | ||
| 18 | UString s2 ('\"'); | ||
| 19 | s2 += s; | ||
| 20 | s2 += '\"'; | ||
| 21 | return s2; | ||
| 22 | } | ||
| 23 | #endif | ||
| 24 | |||
| 25 | WRes CProcess::Create(LPCWSTR imageName, const UString ¶ms, LPCWSTR curDir) | ||
| 26 | { | ||
| 27 | /* | ||
| 28 | OutputDebugStringW(L"CProcess::Create"); | ||
| 29 | OutputDebugStringW(imageName); | ||
| 30 | if (params) | ||
| 31 | { | ||
| 32 | OutputDebugStringW(L"params:"); | ||
| 33 | OutputDebugStringW(params); | ||
| 34 | } | ||
| 35 | if (curDir) | ||
| 36 | { | ||
| 37 | OutputDebugStringW(L"cur dir:"); | ||
| 38 | OutputDebugStringW(curDir); | ||
| 39 | } | ||
| 40 | */ | ||
| 41 | |||
| 42 | Close(); | ||
| 43 | const UString params2 = | ||
| 44 | #ifndef UNDER_CE | ||
| 45 | GetQuotedString(imageName) + L' ' + | ||
| 46 | #endif | ||
| 47 | params; | ||
| 48 | #ifdef UNDER_CE | ||
| 49 | curDir = 0; | ||
| 50 | #else | ||
| 51 | imageName = 0; | ||
| 52 | #endif | ||
| 53 | PROCESS_INFORMATION pi; | ||
| 54 | BOOL result; | ||
| 55 | #ifndef _UNICODE | ||
| 56 | if (!g_IsNT) | ||
| 57 | { | ||
| 58 | STARTUPINFOA si; | ||
| 59 | si.cb = sizeof(si); | ||
| 60 | si.lpReserved = 0; | ||
| 61 | si.lpDesktop = 0; | ||
| 62 | si.lpTitle = 0; | ||
| 63 | si.dwFlags = 0; | ||
| 64 | si.cbReserved2 = 0; | ||
| 65 | si.lpReserved2 = 0; | ||
| 66 | |||
| 67 | CSysString curDirA; | ||
| 68 | if (curDir != 0) | ||
| 69 | curDirA = GetSystemString(curDir); | ||
| 70 | const AString s = GetSystemString(params2); | ||
| 71 | result = ::CreateProcessA(NULL, s.Ptr_non_const(), | ||
| 72 | NULL, NULL, FALSE, 0, NULL, ((curDir != 0) ? (LPCSTR)curDirA: 0), &si, &pi); | ||
| 73 | } | ||
| 74 | else | ||
| 75 | #endif | ||
| 76 | { | ||
| 77 | STARTUPINFOW si; | ||
| 78 | si.cb = sizeof(si); | ||
| 79 | si.lpReserved = 0; | ||
| 80 | si.lpDesktop = 0; | ||
| 81 | si.lpTitle = 0; | ||
| 82 | si.dwFlags = 0; | ||
| 83 | si.cbReserved2 = 0; | ||
| 84 | si.lpReserved2 = 0; | ||
| 85 | |||
| 86 | result = CreateProcessW(imageName, params2.Ptr_non_const(), | ||
| 87 | NULL, NULL, FALSE, 0, NULL, curDir, &si, &pi); | ||
| 88 | } | ||
| 89 | if (result == 0) | ||
| 90 | return ::GetLastError(); | ||
| 91 | ::CloseHandle(pi.hThread); | ||
| 92 | _handle = pi.hProcess; | ||
| 93 | return 0; | ||
| 94 | } | ||
| 95 | |||
| 96 | WRes MyCreateProcess(LPCWSTR imageName, const UString ¶ms) | ||
| 97 | { | ||
| 98 | CProcess process; | ||
| 99 | return process.Create(imageName, params, 0); | ||
| 100 | } | ||
| 101 | |||
| 102 | } | ||
