annotate packaging/desktopshellrun.cpp @ 1118:fd85a02d771d

(issue54) Implement a privilege drop to execute the program after installation. This commit is extremly ugly as I accidentally worked in a working tree that was partially merged with default. To review the real change please check the commit that will merge this branch into default.
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 16 Sep 2014 19:45:19 +0200
parents
children 4a17c9f977d0
rev   line source
1118
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
3 *
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
6 * See LICENSE.txt for details.
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
7 */
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
8
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
9 /**
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
10 * @file tasksched_run_as.cpp
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
11 * @brief Run a command with the Task Scheduler API
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
12 *
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
13 * This effectively starts a program as the user regardles of the current
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
14 * process token.
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
15 */
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
16 #include <windows.h>
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
17 #include "logging.h"
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
18 #include "strhelp.h"
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
19
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
20 #ifndef INITGUID
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
21 #define INITGUID
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
22 #endif
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
23
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
24 #include <initguid.h>
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
25 #include <mstask.h>
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
26 #include <wchar.h>
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
27 #include <ole2.h>
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
28 #include <shldisp.h>
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
29 #include <shobjidl.h>
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
30 #include <exdisp.h>
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
31 #include <shlguid.h>
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
32
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
33 /* Some declarations missing in mingw-w64 3.1.0 taken from msdn */
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
34
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
35 __CRT_UUID_DECL(IShellWindows, 0x85CB6900, 0x4D95, 0x11CF,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
36 0x96, 0x0C, 0x00, 0x80, 0xC7, 0xF4, 0xEE, 0x85);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
37
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
38 DEFINE_GUID(IID_IShellWindows,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
39 0x85CB6900, 0x4D95, 0x11CF,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
40 0x96, 0x0C, 0x00, 0x80, 0xC7, 0xF4, 0xEE, 0x85);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
41 DEFINE_GUID(CLSID_ShellWindows,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
42 0x9BA05972, 0xF6A8, 0x11CF,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
43 0xA4, 0x42, 0x00, 0xA0, 0xC9, 0x0A, 0x8F, 0x39);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
44
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
45
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
46 __CRT_UUID_DECL(IShellDispatch2, 0xA4C6892C, 0x3BA9, 0x11d2,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
47 0x9D, 0xEA, 0x00, 0xC0, 0x4F, 0xB1, 0x61, 0x62);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
48 __CRT_UUID_DECL(IShellFolderViewDual, 0xe7a1af80, 0x4d96,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
49 0x11cf, 0x96, 0x0c, 0x00, 0x80, 0xc7, 0xf4, 0xee, 0x85);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
50
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
51 #ifndef SWC_DESKTOP /* Will probably be addedd in future mingw */
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
52 #define SWC_DESKTOP 0x00000008
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
53 /* from http://msdn.microsoft.com/en-us/library/windows/desktop/cc836581%28v=vs.85%29.aspx */
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
54 #endif
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
55
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
56 #undef INITGUID
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
57
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
58 #ifdef DO_RELEASE_BUILD
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
59 bool g_debug = false;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
60 #else
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
61 bool g_debug = true;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
62 #endif
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
63
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
64 typedef struct _stack_t
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
65 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
66 struct _stack_t *next;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
67 char text[1]; /* This should be the length of string_size. */
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
68 } stack_t;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
69
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
70 static HINSTANCE g_hInstance; /* Our Instance. */
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
71
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
72 #define UNUSED(x) (void)(x)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
73
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
74 /** @brief the actual execuation call on the shell dispatcher
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
75 *
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
76 * @param[in] disp The shell dispatcher to use for shell execute.
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
77 * @param[in] fName The file that should be exectued.
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
78 *
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
79 * @returns true on success.
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
80 */
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
81 static bool
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
82 shellexecute(IShellDispatch2 *disp, wchar_t *fName)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
83 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
84 BSTR bName = NULL,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
85 bParam = NULL,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
86 bDir = NULL,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
87 bOp = NULL;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
88 VARIANT vParams[4];
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
89 HRESULT hr;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
90
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
91 if (!fName || !disp)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
92 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
93 ERRORPRINTF ("Invalid call to shellexecute.");
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
94 return false;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
95 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
96
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
97 bName = SysAllocString(fName);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
98 bParam = SysAllocString(L"");
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
99 bDir = SysAllocString(L"");
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
100 bOp = SysAllocString(L"");
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
101
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
102 if (!bName || !bParam || !bDir || !bOp)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
103 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
104 /* Out of memory */
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
105 ERRORPRINTF ("Failed to allocate bstr values ");
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
106 return false;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
107 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
108
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
109 vParams[0].vt = VT_BSTR;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
110 vParams[0].bstrVal = bParam;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
111 vParams[1].vt = VT_BSTR;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
112 vParams[1].bstrVal = bDir;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
113 vParams[2].vt = VT_BSTR;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
114 vParams[2].bstrVal = bOp;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
115 vParams[3].vt = VT_INT;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
116 vParams[3].intVal = SW_SHOWNORMAL;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
117
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
118 hr = disp->ShellExecute(bName, vParams[0], vParams[1], vParams[2], vParams[3]);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
119
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
120 SysFreeString(bName);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
121 SysFreeString(bParam);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
122 SysFreeString(bOp);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
123 SysFreeString(bDir);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
124
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
125 if (FAILED(hr))
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
126 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
127 ERRORPRINTF ("Failed to execute.");
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
128 return false;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
129 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
130 return true;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
131 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
132
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
133 #ifdef __cplusplus
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
134 extern "C" {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
135 #endif
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
136
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
137 /* Standard entry point for DLLs. */
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
138 int WINAPI
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
139 DllMain (HANDLE hinst, DWORD reason, LPVOID reserved)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
140 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
141 UNUSED(reserved);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
142 if (reason == DLL_PROCESS_ATTACH)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
143 g_hInstance = (HINSTANCE)hinst;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
144 return TRUE;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
145 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
146
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
147 /** @brief Execute a command with the current running shell.
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
148 *
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
149 * This function is intended to be called when you want to
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
150 * make sure that your application is not executed with higher
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
151 * privileges then the normal desktop session.
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
152 *
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
153 * The code is based on the idea:
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
154 * http://blogs.msdn.com/b/oldnewthing/archive/2013/11/18/10468726.aspx
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
155 *
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
156 * The function signature is explained by NSIS.
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
157 */
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
158 void __declspec(dllexport) __cdecl Exec(HWND hwndParent,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
159 int string_size,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
160 char *variables,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
161 stack_t **stacktop)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
162 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
163 UNUSED(hwndParent);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
164 UNUSED(string_size);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
165 HRESULT hr;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
166 wchar_t *wbuf = NULL;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
167 IShellWindows *shellWindows = NULL;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
168 IShellBrowser *shellBrowser = NULL;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
169 IShellView *shellView = NULL;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
170 IShellFolderViewDual *folderView = NULL;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
171 IShellDispatch2 *shellDispatch = NULL;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
172 IServiceProvider *serviceProv = NULL;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
173 HWND hwnd;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
174 IDispatch *disp = NULL,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
175 *bgDisp = NULL,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
176 *sDisp = NULL;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
177 VARIANT vEmpty = {};
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
178
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
179
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
180 if (!stacktop || !*stacktop || !(*stacktop)->text)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
181 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
182 ERRORPRINTF ("Invalid call to exec :");
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
183 return;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
184 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
185
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
186 /* Initialize com ctx */
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
187 hr = CoInitialize(NULL);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
188 if(FAILED(hr))
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
189 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
190 ERRORPRINTF ("CoInitializeEx failed. error = 0x%lx.", hr);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
191 return;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
192 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
193
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
194 /* Get the shell interface */
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
195 hr = CoCreateInstance(CLSID_ShellWindows,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
196 NULL, CLSCTX_LOCAL_SERVER,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
197 IID_PPV_ARGS(&shellWindows));
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
198 if (FAILED(hr))
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
199 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
200 ERRORPRINTF ("Failed to get shell interface.");
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
201 goto done;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
202 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
203
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
204 /* Get the desktop shell window */
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
205 hr = shellWindows->FindWindowSW(&vEmpty,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
206 &vEmpty,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
207 SWC_DESKTOP,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
208 (long*)&hwnd,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
209 SWFO_NEEDDISPATCH,
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
210 &disp);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
211 if (FAILED(hr))
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
212 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
213 ERRORPRINTF ("Failed to find the desktop dispatcher.");
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
214 goto done;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
215 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
216
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
217 hr = disp->QueryInterface(IID_PPV_ARGS(&serviceProv));
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
218
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
219 if (FAILED(hr))
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
220 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
221 ERRORPRINTF ("Failed to get the service provider.");
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
222 goto done;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
223 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
224
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
225 /* Get the shell browser */
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
226 hr = serviceProv->QueryService(SID_STopLevelBrowser, IID_PPV_ARGS(&shellBrowser));
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
227 if (FAILED(hr))
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
228 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
229 ERRORPRINTF ("Failed to find the top level browser.");
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
230 goto done;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
231 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
232
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
233 hr = shellBrowser->QueryActiveShellView(&shellView);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
234
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
235 if (FAILED(hr))
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
236 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
237 ERRORPRINTF ("Failed to find the active view.");
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
238 goto done;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
239 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
240
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
241 hr = shellView->GetItemObject(SVGIO_BACKGROUND, IID_PPV_ARGS(&bgDisp));
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
242
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
243 if (FAILED(hr))
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
244 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
245 ERRORPRINTF ("Failed to get the views background.");
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
246 goto done;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
247 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
248
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
249 hr = bgDisp->QueryInterface(IID_PPV_ARGS(&folderView));
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
250
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
251 if (FAILED(hr))
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
252 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
253 ERRORPRINTF ("Failed to get the folder view.");
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
254 goto done;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
255 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
256
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
257
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
258 hr = folderView->get_Application(&sDisp);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
259
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
260 if (FAILED(hr))
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
261 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
262 ERRORPRINTF ("Failed to get the shell dispatch.");
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
263 goto done;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
264 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
265
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
266 hr = sDisp->QueryInterface(IID_PPV_ARGS(&shellDispatch));
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
267
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
268 if (FAILED(hr))
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
269 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
270 ERRORPRINTF ("Failed to get the shell dispatch interface.");
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
271 goto done;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
272 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
273
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
274 wbuf = utf8_to_wchar((*stacktop)->text, strlen((*stacktop)->text));
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
275 if (!wbuf)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
276 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
277 ERRORPRINTF ("Failed to convert argument to wchar. error = 0x%lx.", hr);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
278 goto done;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
279 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
280
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
281 if (!shellexecute(shellDispatch, wbuf))
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
282 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
283 ERRORPRINTF ("Failed to execute.");
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
284 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
285 xfree (wbuf);
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
286 done:
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
287 if (folderView)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
288 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
289 folderView->Release();
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
290 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
291 if (disp)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
292 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
293 disp->Release();
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
294 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
295 if (shellBrowser)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
296 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
297 shellBrowser->Release();
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
298 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
299 if (shellWindows)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
300 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
301 shellWindows->Release();
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
302 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
303 if (shellView)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
304 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
305 shellView->Release();
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
306 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
307 if (sDisp)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
308 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
309 sDisp->Release();
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
310 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
311 if (shellDispatch)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
312 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
313 shellDispatch->Release();
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
314 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
315 if (serviceProv)
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
316 {
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
317 serviceProv->Release();
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
318 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
319 CoUninitialize();
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
320 return;
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
321 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
322 #ifdef __cplusplus
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
323 }
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
324 #endif
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
325
fd85a02d771d (issue54) Implement a privilege drop to execute the program after installation.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
326

http://wald.intevation.org/projects/trustbridge/