1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TestSysShExec.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_shell.hxx"
35 //-----------------------------------------------------------
37 //-----------------------------------------------------------
38 #include <com/sun/star/lang/XComponent.hpp>
39 #include <com/sun/star/registry/XSimpleRegistry.hpp>
41 #ifndef _COM_SUN_STAR_SYS_SHELL_XSYSTEMSHELLEXECUTE_HPP_
42 #include <com/sun/star/system/XSystemShellExecute.hpp>
44 #include <cppuhelper/servicefactory.hxx>
47 #include <osl/file.hxx>
49 //--------------------------------------------------------------
51 //--------------------------------------------------------------
52 #include <cppuhelper/servicefactory.hxx>
53 #include <rtl/ustring.hxx>
54 #include <sal/types.h>
55 #include <osl/diagnose.h>
60 #pragma warning(push, 1)
67 //--------------------------------------------------------------
69 //--------------------------------------------------------------
71 using namespace ::rtl
;
72 using namespace ::cppu
;
73 using namespace ::com::sun::star::uno
;
74 using namespace ::com::sun::star::lang
;
76 using namespace com::sun::star::system
;
78 //--------------------------------------------------------------
80 //--------------------------------------------------------------
82 #define RDB_SYSPATH "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\applicat.rdb"
84 //--------------------------------------------------------------
86 //--------------------------------------------------------------
88 Reference
< XMultiServiceFactory
> g_xFactory
;
91 //--------------------------------------------------------------
93 //--------------------------------------------------------------
96 // int SAL_CALL main(int nArgc, char* Argv[], char* Env[] )
97 int SAL_CALL
main(int nArgc
, char* Argv
[], char* )
99 //-------------------------------------------------
100 // get the global service-manager
101 //-------------------------------------------------
106 // Get global factory for uno services.
107 OUString rdbName
= OUString( RTL_CONSTASCII_USTRINGPARAM( RDB_SYSPATH
) );
108 Reference
< XMultiServiceFactory
> g_xFactory( createRegistryServiceFactory( rdbName
) );
110 // Print a message if an error occured.
111 if ( g_xFactory
.is() == sal_False
)
113 OSL_ENSURE(sal_False
, "Can't create RegistryServiceFactory");
117 printf("Creating RegistryServiceFactory successful\n");
119 //-------------------------------------------------
120 // try to get an Interface to a XFilePicker Service
121 //-------------------------------------------------
123 Reference
< XSystemShellExecute
> xSysShExec(
124 g_xFactory
->createInstance( OUString::createFromAscii( "com.sun.star.system.SystemShellExecute" ) ), UNO_QUERY
);
126 if ( !xSysShExec
.is() )
128 OSL_ENSURE( sal_False
, "Error creating SystemShellExecute Service" );
132 //"c:\\winnt\\notepad.exe"
133 OUString cmd
= OUString::createFromAscii( Argv
[1] );
134 OUString param
= OUString::createFromAscii( Argv
[2] ); //c:\\winnt\\iis5.log
138 xSysShExec
->execute( cmd
, param
, atoi( Argv
[3] ) );
140 catch( SystemShellExecuteException
& )
142 OSL_ENSURE( sal_False
, "Error executing system command" );
144 catch( IllegalArgumentException
& )
146 OSL_ENSURE( sal_False
, "Invalid parameter" );
149 //--------------------------------------------------
151 //--------------------------------------------------
153 // Cast factory to XComponent
154 Reference
< XComponent
> xComponent( g_xFactory
, UNO_QUERY
);
156 // Print a message if an error occured.
157 if ( xComponent
.is() == sal_False
)
159 OSL_ENSURE(sal_False
, "Error shuting down");
162 // Dispose and clear factory
163 xComponent
->dispose();
165 g_xFactory
= Reference
< XMultiServiceFactory
>();
167 printf("Test successful\n");