1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
// ProcessUtils.cpp
#include "StdAfx.h"
#include "../Common/StringConvert.h"
#include "ProcessUtils.h"
#ifndef _UNICODE
extern bool g_IsNT;
#endif
namespace NWindows {
#ifndef UNDER_CE
static UString GetQuotedString(const UString &s)
{
UString s2 ('\"');
s2 += s;
s2.Add_Char('\"');
return s2;
}
#endif
WRes CProcess::Create(LPCWSTR imageName, const UString ¶ms, LPCWSTR curDir)
{
/*
OutputDebugStringW(L"CProcess::Create");
OutputDebugStringW(imageName);
if (params)
{
OutputDebugStringW(L"params:");
OutputDebugStringW(params);
}
if (curDir)
{
OutputDebugStringW(L"cur dir:");
OutputDebugStringW(curDir);
}
*/
Close();
const UString params2 =
#ifndef UNDER_CE
GetQuotedString(imageName) + L' ' +
#endif
params;
#ifdef UNDER_CE
curDir = NULL;
#else
imageName = NULL;
#endif
PROCESS_INFORMATION pi;
BOOL result;
#ifndef _UNICODE
if (!g_IsNT)
{
STARTUPINFOA si;
si.cb = sizeof(si);
si.lpReserved = NULL;
si.lpDesktop = NULL;
si.lpTitle = NULL;
si.dwFlags = 0;
si.cbReserved2 = 0;
si.lpReserved2 = NULL;
CSysString curDirA;
if (curDir != 0)
curDirA = GetSystemString(curDir);
const AString s = GetSystemString(params2);
result = ::CreateProcessA(NULL, s.Ptr_non_const(),
NULL, NULL, FALSE, 0, NULL, ((curDir != 0) ? (LPCSTR)curDirA: 0), &si, &pi);
}
else
#endif
{
STARTUPINFOW si;
si.cb = sizeof(si);
si.lpReserved = NULL;
si.lpDesktop = NULL;
si.lpTitle = NULL;
si.dwFlags = 0;
si.cbReserved2 = 0;
si.lpReserved2 = NULL;
result = CreateProcessW(imageName, params2.Ptr_non_const(),
NULL, NULL, FALSE, 0, NULL, curDir, &si, &pi);
}
if (result == 0)
return ::GetLastError();
::CloseHandle(pi.hThread);
_handle = pi.hProcess;
return 0;
}
WRes MyCreateProcess(LPCWSTR imageName, const UString ¶ms)
{
CProcess process;
return process.Create(imageName, params, NULL);
}
}
|