xref: /aoo41x/main/shell/source/win32/SysShExec.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_shell.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir //------------------------------------------------------------------------
32*cdf0e10cSrcweir // includes
33*cdf0e10cSrcweir //------------------------------------------------------------------------
34*cdf0e10cSrcweir #include <osl/diagnose.h>
35*cdf0e10cSrcweir #include "SysShExec.hxx"
36*cdf0e10cSrcweir #include <osl/file.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SYS_SHELL_SYSTEMSHELLEXECUTEFLAGS_HPP_
39*cdf0e10cSrcweir #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
40*cdf0e10cSrcweir #endif
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #define WIN32_LEAN_AND_MEAN
43*cdf0e10cSrcweir #if defined _MSC_VER
44*cdf0e10cSrcweir #pragma warning(push, 1)
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir #include <windows.h>
47*cdf0e10cSrcweir #include <shellapi.h>
48*cdf0e10cSrcweir #include <objbase.h>
49*cdf0e10cSrcweir #if defined _MSC_VER
50*cdf0e10cSrcweir #pragma warning(pop)
51*cdf0e10cSrcweir #endif
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir //------------------------------------------------------------------------
54*cdf0e10cSrcweir // namespace directives
55*cdf0e10cSrcweir //------------------------------------------------------------------------
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir using com::sun::star::uno::Reference;
58*cdf0e10cSrcweir using com::sun::star::uno::RuntimeException;
59*cdf0e10cSrcweir using com::sun::star::uno::Sequence;
60*cdf0e10cSrcweir using com::sun::star::uno::XInterface;
61*cdf0e10cSrcweir using com::sun::star::lang::EventObject;
62*cdf0e10cSrcweir using com::sun::star::lang::XServiceInfo;
63*cdf0e10cSrcweir using com::sun::star::lang::IllegalArgumentException;
64*cdf0e10cSrcweir using rtl::OUString;
65*cdf0e10cSrcweir using osl::Mutex;
66*cdf0e10cSrcweir using com::sun::star::system::XSystemShellExecute;
67*cdf0e10cSrcweir using com::sun::star::system::SystemShellExecuteException;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir using namespace ::com::sun::star::system::SystemShellExecuteFlags;
70*cdf0e10cSrcweir using namespace cppu;
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir //------------------------------------------------------------------------
73*cdf0e10cSrcweir // defines
74*cdf0e10cSrcweir //------------------------------------------------------------------------
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir #define SYSSHEXEC_IMPL_NAME  "com.sun.star.sys.shell.SystemShellExecute"
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir //------------------------------------------------------------------------
79*cdf0e10cSrcweir // helper functions
80*cdf0e10cSrcweir //------------------------------------------------------------------------
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir namespace // private
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir 	Sequence< OUString > SAL_CALL SysShExec_getSupportedServiceNames()
85*cdf0e10cSrcweir 	{
86*cdf0e10cSrcweir 		Sequence< OUString > aRet(1);
87*cdf0e10cSrcweir 		aRet[0] = OUString::createFromAscii("com.sun.star.sys.shell.SystemShellExecute");
88*cdf0e10cSrcweir 		return aRet;
89*cdf0e10cSrcweir 	}
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     /* This is the error table that defines the mapping between OS error
92*cdf0e10cSrcweir     codes and errno values */
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir     struct errentry {
95*cdf0e10cSrcweir         unsigned long oscode;	/* OS return value */
96*cdf0e10cSrcweir         int errnocode;			/* System V error code */
97*cdf0e10cSrcweir     };
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir     struct errentry errtable[] = {
100*cdf0e10cSrcweir         {  ERROR_SUCCESS,				 osl_File_E_None     },  /* 0 */
101*cdf0e10cSrcweir         {  ERROR_INVALID_FUNCTION,       osl_File_E_INVAL    },  /* 1 */
102*cdf0e10cSrcweir         {  ERROR_FILE_NOT_FOUND,         osl_File_E_NOENT    },  /* 2 */
103*cdf0e10cSrcweir         {  ERROR_PATH_NOT_FOUND,         osl_File_E_NOENT    },  /* 3 */
104*cdf0e10cSrcweir         {  ERROR_TOO_MANY_OPEN_FILES,    osl_File_E_MFILE    },  /* 4 */
105*cdf0e10cSrcweir         {  ERROR_ACCESS_DENIED,          osl_File_E_ACCES    },  /* 5 */
106*cdf0e10cSrcweir         {  ERROR_INVALID_HANDLE,         osl_File_E_BADF     },  /* 6 */
107*cdf0e10cSrcweir         {  ERROR_ARENA_TRASHED,          osl_File_E_NOMEM    },  /* 7 */
108*cdf0e10cSrcweir         {  ERROR_NOT_ENOUGH_MEMORY,      osl_File_E_NOMEM    },  /* 8 */
109*cdf0e10cSrcweir         {  ERROR_INVALID_BLOCK,          osl_File_E_NOMEM    },  /* 9 */
110*cdf0e10cSrcweir         {  ERROR_BAD_ENVIRONMENT,        osl_File_E_2BIG     },  /* 10 */
111*cdf0e10cSrcweir         {  ERROR_BAD_FORMAT,             osl_File_E_NOEXEC   },  /* 11 */
112*cdf0e10cSrcweir         {  ERROR_INVALID_ACCESS,         osl_File_E_INVAL    },  /* 12 */
113*cdf0e10cSrcweir         {  ERROR_INVALID_DATA,           osl_File_E_INVAL    },  /* 13 */
114*cdf0e10cSrcweir         {  ERROR_INVALID_DRIVE,          osl_File_E_NOENT    },  /* 15 */
115*cdf0e10cSrcweir         {  ERROR_CURRENT_DIRECTORY,      osl_File_E_ACCES    },  /* 16 */
116*cdf0e10cSrcweir         {  ERROR_NOT_SAME_DEVICE,        osl_File_E_XDEV     },  /* 17 */
117*cdf0e10cSrcweir         {  ERROR_NO_MORE_FILES,          osl_File_E_NOENT    },  /* 18 */
118*cdf0e10cSrcweir         {  ERROR_LOCK_VIOLATION,         osl_File_E_ACCES    },  /* 33 */
119*cdf0e10cSrcweir         {  ERROR_BAD_NETPATH,            osl_File_E_NOENT    },  /* 53 */
120*cdf0e10cSrcweir         {  ERROR_NETWORK_ACCESS_DENIED,  osl_File_E_ACCES    },  /* 65 */
121*cdf0e10cSrcweir         {  ERROR_BAD_NET_NAME,           osl_File_E_NOENT    },  /* 67 */
122*cdf0e10cSrcweir         {  ERROR_FILE_EXISTS,            osl_File_E_EXIST    },  /* 80 */
123*cdf0e10cSrcweir         {  ERROR_CANNOT_MAKE,            osl_File_E_ACCES    },  /* 82 */
124*cdf0e10cSrcweir         {  ERROR_FAIL_I24,               osl_File_E_ACCES    },  /* 83 */
125*cdf0e10cSrcweir         {  ERROR_INVALID_PARAMETER,      osl_File_E_INVAL    },  /* 87 */
126*cdf0e10cSrcweir         {  ERROR_NO_PROC_SLOTS,          osl_File_E_AGAIN    },  /* 89 */
127*cdf0e10cSrcweir         {  ERROR_DRIVE_LOCKED,           osl_File_E_ACCES    },  /* 108 */
128*cdf0e10cSrcweir         {  ERROR_BROKEN_PIPE,            osl_File_E_PIPE     },  /* 109 */
129*cdf0e10cSrcweir         {  ERROR_DISK_FULL,              osl_File_E_NOSPC    },  /* 112 */
130*cdf0e10cSrcweir         {  ERROR_INVALID_TARGET_HANDLE,  osl_File_E_BADF     },  /* 114 */
131*cdf0e10cSrcweir         {  ERROR_INVALID_HANDLE,         osl_File_E_INVAL    },  /* 124 */
132*cdf0e10cSrcweir         {  ERROR_WAIT_NO_CHILDREN,       osl_File_E_CHILD    },  /* 128 */
133*cdf0e10cSrcweir         {  ERROR_CHILD_NOT_COMPLETE,     osl_File_E_CHILD    },  /* 129 */
134*cdf0e10cSrcweir         {  ERROR_DIRECT_ACCESS_HANDLE,   osl_File_E_BADF     },  /* 130 */
135*cdf0e10cSrcweir         {  ERROR_NEGATIVE_SEEK,          osl_File_E_INVAL    },  /* 131 */
136*cdf0e10cSrcweir         {  ERROR_SEEK_ON_DEVICE,         osl_File_E_ACCES    },  /* 132 */
137*cdf0e10cSrcweir         {  ERROR_DIR_NOT_EMPTY,          osl_File_E_NOTEMPTY },  /* 145 */
138*cdf0e10cSrcweir         {  ERROR_NOT_LOCKED,             osl_File_E_ACCES    },  /* 158 */
139*cdf0e10cSrcweir         {  ERROR_BAD_PATHNAME,           osl_File_E_NOENT    },  /* 161 */
140*cdf0e10cSrcweir         {  ERROR_MAX_THRDS_REACHED,      osl_File_E_AGAIN    },  /* 164 */
141*cdf0e10cSrcweir         {  ERROR_LOCK_FAILED,            osl_File_E_ACCES    },  /* 167 */
142*cdf0e10cSrcweir         {  ERROR_ALREADY_EXISTS,         osl_File_E_EXIST    },  /* 183 */
143*cdf0e10cSrcweir         {  ERROR_FILENAME_EXCED_RANGE,   osl_File_E_NOENT    },  /* 206 */
144*cdf0e10cSrcweir         {  ERROR_NESTING_NOT_ALLOWED,    osl_File_E_AGAIN    },  /* 215 */
145*cdf0e10cSrcweir         {  ERROR_NOT_ENOUGH_QUOTA,       osl_File_E_NOMEM    }    /* 1816 */
146*cdf0e10cSrcweir     };
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir     /* size of the table */
149*cdf0e10cSrcweir     #define ERRTABLESIZE (sizeof(errtable)/sizeof(errtable[0]))
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir     /* The following two constants must be the minimum and maximum
152*cdf0e10cSrcweir     values in the (contiguous) range of osl_File_E_xec Failure errors. */
153*cdf0e10cSrcweir     #define MIN_EXEC_ERROR ERROR_INVALID_STARTING_CODESEG
154*cdf0e10cSrcweir     #define MAX_EXEC_ERROR ERROR_INFLOOP_IN_RELOC_CHAIN
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     /* These are the low and high value in the range of errors that are
157*cdf0e10cSrcweir     access violations */
158*cdf0e10cSrcweir     #define MIN_EACCES_RANGE ERROR_WRITE_PROTECT
159*cdf0e10cSrcweir     #define MAX_EACCES_RANGE ERROR_SHARING_BUFFER_EXCEEDED
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir     /*******************************************************************************/
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir     oslFileError _mapError( DWORD dwError )
165*cdf0e10cSrcweir     {
166*cdf0e10cSrcweir         int i;
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir         /* check the table for the OS error code */
169*cdf0e10cSrcweir         for ( i = 0; i < ERRTABLESIZE; ++i )
170*cdf0e10cSrcweir 	    {
171*cdf0e10cSrcweir 		    if ( dwError == errtable[i].oscode )
172*cdf0e10cSrcweir 			    return (oslFileError)errtable[i].errnocode;
173*cdf0e10cSrcweir         }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir         /* The error code wasn't in the table.  We check for a range of */
176*cdf0e10cSrcweir         /* osl_File_E_ACCES errors or exec failure errors (ENOEXEC).  Otherwise   */
177*cdf0e10cSrcweir         /* osl_File_E_INVAL is returned.                                          */
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir         if ( dwError >= MIN_EACCES_RANGE && dwError <= MAX_EACCES_RANGE)
180*cdf0e10cSrcweir 		    return osl_File_E_ACCES;
181*cdf0e10cSrcweir         else if ( dwError >= MIN_EXEC_ERROR && dwError <= MAX_EXEC_ERROR)
182*cdf0e10cSrcweir 		    return osl_File_E_NOEXEC;
183*cdf0e10cSrcweir         else
184*cdf0e10cSrcweir 		    return osl_File_E_INVAL;
185*cdf0e10cSrcweir     }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir     #define MapError( oserror )	_mapError( oserror )
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir     #define E_UNKNOWN_EXEC_ERROR -1
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     //-----------------------------------------
192*cdf0e10cSrcweir     //-----------------------------------------
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir     bool is_system_path(const OUString& path_or_uri)
195*cdf0e10cSrcweir     {
196*cdf0e10cSrcweir         OUString url;
197*cdf0e10cSrcweir         osl::FileBase::RC rc = osl::FileBase::getFileURLFromSystemPath(path_or_uri, url);
198*cdf0e10cSrcweir         return (rc == osl::FileBase::E_None);
199*cdf0e10cSrcweir     }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir     //-----------------------------------------
202*cdf0e10cSrcweir     // trying to identify a jump mark
203*cdf0e10cSrcweir     //-----------------------------------------
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir     const OUString    JUMP_MARK_HTM  = OUString::createFromAscii(".htm#");
206*cdf0e10cSrcweir     const OUString    JUMP_MARK_HTML = OUString::createFromAscii(".html#");
207*cdf0e10cSrcweir     const sal_Unicode HASH_MARK      = (sal_Unicode)'#';
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir     bool has_jump_mark(const OUString& system_path, sal_Int32* jmp_mark_start = NULL)
210*cdf0e10cSrcweir     {
211*cdf0e10cSrcweir         sal_Int32 jmp_mark = std::max<int>(
212*cdf0e10cSrcweir             system_path.lastIndexOf(JUMP_MARK_HTM),
213*cdf0e10cSrcweir             system_path.lastIndexOf(JUMP_MARK_HTML));
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir         if (jmp_mark_start)
216*cdf0e10cSrcweir             *jmp_mark_start = jmp_mark;
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir         return (jmp_mark > -1);
219*cdf0e10cSrcweir     }
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir     //-----------------------------------------
222*cdf0e10cSrcweir     //-----------------------------------------
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir     bool is_existing_file(const OUString& file_name)
225*cdf0e10cSrcweir     {
226*cdf0e10cSrcweir         OSL_ASSERT(is_system_path(file_name));
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir         bool exist = false;
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir         OUString file_url;
231*cdf0e10cSrcweir         osl::FileBase::RC rc = osl::FileBase::getFileURLFromSystemPath(file_name, file_url);
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir         if (osl::FileBase::E_None == rc)
234*cdf0e10cSrcweir         {
235*cdf0e10cSrcweir             osl::DirectoryItem dir_item;
236*cdf0e10cSrcweir             rc = osl::DirectoryItem::get(file_url, dir_item);
237*cdf0e10cSrcweir             exist = (osl::FileBase::E_None == rc);
238*cdf0e10cSrcweir         }
239*cdf0e10cSrcweir         return exist;
240*cdf0e10cSrcweir     }
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir     //-------------------------------------------------
243*cdf0e10cSrcweir     // Jump marks in file urls are illegal.
244*cdf0e10cSrcweir     //-------------------------------------------------
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir     void remove_jump_mark(OUString* p_command)
247*cdf0e10cSrcweir     {
248*cdf0e10cSrcweir         OSL_PRECOND(p_command, "invalid parameter");
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir         sal_Int32 pos;
251*cdf0e10cSrcweir         if (has_jump_mark(*p_command, &pos))
252*cdf0e10cSrcweir         {
253*cdf0e10cSrcweir             const sal_Unicode* p_jmp_mark = p_command->getStr() + pos;
254*cdf0e10cSrcweir             while (*p_jmp_mark && (*p_jmp_mark != HASH_MARK))
255*cdf0e10cSrcweir                 p_jmp_mark++;
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir             *p_command = OUString(p_command->getStr(), p_jmp_mark - p_command->getStr());
258*cdf0e10cSrcweir         }
259*cdf0e10cSrcweir     }
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir } // end namespace
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
264*cdf0e10cSrcweir //
265*cdf0e10cSrcweir //-----------------------------------------------------------------------------------------
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir CSysShExec::CSysShExec( ) :
268*cdf0e10cSrcweir 	WeakComponentImplHelper2< XSystemShellExecute, XServiceInfo >( m_aMutex )
269*cdf0e10cSrcweir {
270*cdf0e10cSrcweir     /*
271*cdf0e10cSrcweir      * As this service is declared thread-affine, it is ensured to be called from a
272*cdf0e10cSrcweir      * dedicated thread, so initialize COM here.
273*cdf0e10cSrcweir      *
274*cdf0e10cSrcweir      * We need COM to be initialized for STA, but osl thread get initialized for MTA.
275*cdf0e10cSrcweir      * Once this changed, we can remove the uninitialize call.
276*cdf0e10cSrcweir      */
277*cdf0e10cSrcweir     CoUninitialize();
278*cdf0e10cSrcweir     CoInitialize( NULL );
279*cdf0e10cSrcweir }
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir //-------------------------------------------------
282*cdf0e10cSrcweir //
283*cdf0e10cSrcweir //-------------------------------------------------
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir void SAL_CALL CSysShExec::execute( const OUString& aCommand, const OUString& aParameter, sal_Int32 nFlags )
286*cdf0e10cSrcweir         throw (IllegalArgumentException, SystemShellExecuteException, RuntimeException)
287*cdf0e10cSrcweir {
288*cdf0e10cSrcweir     // parameter checking
289*cdf0e10cSrcweir     if (0 == aCommand.getLength())
290*cdf0e10cSrcweir         throw IllegalArgumentException(
291*cdf0e10cSrcweir             OUString::createFromAscii( "Empty command" ),
292*cdf0e10cSrcweir             static_cast< XSystemShellExecute* >( this ),
293*cdf0e10cSrcweir             1 );
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir     if (!(nFlags >= DEFAULTS && nFlags <= NO_SYSTEM_ERROR_MESSAGE))
296*cdf0e10cSrcweir         throw IllegalArgumentException(
297*cdf0e10cSrcweir             OUString::createFromAscii( "Invalid Flags specified" ),
298*cdf0e10cSrcweir             static_cast< XSystemShellExecute* >( this ),
299*cdf0e10cSrcweir             3 );
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir     /*  #i4789#; jump mark detection on system paths
302*cdf0e10cSrcweir         if the given command is a system path (not http or
303*cdf0e10cSrcweir         other uri schemes) and seems to have a jump mark
304*cdf0e10cSrcweir         and names no existing file (remeber the jump mark
305*cdf0e10cSrcweir         sign '#' is a valid file name character we remove
306*cdf0e10cSrcweir         the jump mark, else ShellExecuteEx fails */
307*cdf0e10cSrcweir     OUString preprocessed_command(aCommand);
308*cdf0e10cSrcweir     if (is_system_path(preprocessed_command))
309*cdf0e10cSrcweir     {
310*cdf0e10cSrcweir         if (has_jump_mark(preprocessed_command) && !is_existing_file(preprocessed_command))
311*cdf0e10cSrcweir             remove_jump_mark(&preprocessed_command);
312*cdf0e10cSrcweir     }
313*cdf0e10cSrcweir     /* Convert file uris to system paths */
314*cdf0e10cSrcweir     else
315*cdf0e10cSrcweir     {
316*cdf0e10cSrcweir         OUString aSystemPath;
317*cdf0e10cSrcweir         if (::osl::FileBase::E_None == ::osl::FileBase::getSystemPathFromFileURL(preprocessed_command, aSystemPath))
318*cdf0e10cSrcweir             preprocessed_command = aSystemPath;
319*cdf0e10cSrcweir     }
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir     SHELLEXECUTEINFOW sei;
322*cdf0e10cSrcweir     ZeroMemory(&sei, sizeof( sei));
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir     sei.cbSize       = sizeof(sei);
325*cdf0e10cSrcweir     sei.lpFile       = reinterpret_cast<LPCWSTR>(preprocessed_command.getStr());
326*cdf0e10cSrcweir     sei.lpParameters = reinterpret_cast<LPCWSTR>(aParameter.getStr());
327*cdf0e10cSrcweir     sei.nShow        = SW_SHOWNORMAL;
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir     if (NO_SYSTEM_ERROR_MESSAGE & nFlags)
330*cdf0e10cSrcweir         sei.fMask = SEE_MASK_FLAG_NO_UI;
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir     SetLastError( 0 );
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir     sal_Bool bRet = ShellExecuteExW(&sei) ? sal_True : sal_False;
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir     if (!bRet && (nFlags & NO_SYSTEM_ERROR_MESSAGE))
337*cdf0e10cSrcweir     {
338*cdf0e10cSrcweir         // ShellExecuteEx fails to set an error code
339*cdf0e10cSrcweir         // we return osl_File_E_INVAL
340*cdf0e10cSrcweir         sal_Int32 psxErr = GetLastError();
341*cdf0e10cSrcweir         if (ERROR_SUCCESS == psxErr)
342*cdf0e10cSrcweir             psxErr = E_UNKNOWN_EXEC_ERROR;
343*cdf0e10cSrcweir         else
344*cdf0e10cSrcweir             psxErr = MapError(psxErr);
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir         throw SystemShellExecuteException(
347*cdf0e10cSrcweir             OUString::createFromAscii("Error executing command"),
348*cdf0e10cSrcweir             static_cast< XSystemShellExecute* >(this),
349*cdf0e10cSrcweir             psxErr);
350*cdf0e10cSrcweir     }
351*cdf0e10cSrcweir }
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir // -------------------------------------------------
354*cdf0e10cSrcweir // XServiceInfo
355*cdf0e10cSrcweir // -------------------------------------------------
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir OUString SAL_CALL CSysShExec::getImplementationName(  )
358*cdf0e10cSrcweir 	throw( RuntimeException )
359*cdf0e10cSrcweir {
360*cdf0e10cSrcweir 	return OUString::createFromAscii( SYSSHEXEC_IMPL_NAME );
361*cdf0e10cSrcweir }
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir // -------------------------------------------------
364*cdf0e10cSrcweir //	XServiceInfo
365*cdf0e10cSrcweir // -------------------------------------------------
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir sal_Bool SAL_CALL CSysShExec::supportsService( const OUString& ServiceName )
368*cdf0e10cSrcweir 	throw( RuntimeException )
369*cdf0e10cSrcweir {
370*cdf0e10cSrcweir 	Sequence < OUString > SupportedServicesNames = SysShExec_getSupportedServiceNames();
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 	for ( sal_Int32 n = SupportedServicesNames.getLength(); n--; )
373*cdf0e10cSrcweir 		if (SupportedServicesNames[n].compareTo(ServiceName) == 0)
374*cdf0e10cSrcweir 			return sal_True;
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir 	return sal_False;
377*cdf0e10cSrcweir }
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir // -------------------------------------------------
380*cdf0e10cSrcweir //	XServiceInfo
381*cdf0e10cSrcweir // -------------------------------------------------
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir Sequence< OUString > SAL_CALL CSysShExec::getSupportedServiceNames(	 )
384*cdf0e10cSrcweir 	throw( RuntimeException )
385*cdf0e10cSrcweir {
386*cdf0e10cSrcweir 	return SysShExec_getSupportedServiceNames();
387*cdf0e10cSrcweir }
388*cdf0e10cSrcweir 
389