merge the formfield patch from ooo-build
[ooovba.git] / shell / source / win32 / workbench / TestSysShExec.cxx
blob179766e9f9e688a889ad88e0abc761279a811741
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TestSysShExec.cxx,v $
10 * $Revision: 1.7 $
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 //-----------------------------------------------------------
36 // interface includes
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>
43 #endif
44 #include <cppuhelper/servicefactory.hxx>
47 #include <osl/file.hxx>
49 //--------------------------------------------------------------
50 // other includes
51 //--------------------------------------------------------------
52 #include <cppuhelper/servicefactory.hxx>
53 #include <rtl/ustring.hxx>
54 #include <sal/types.h>
55 #include <osl/diagnose.h>
57 #include <stdio.h>
59 #if defined _MSC_VER
60 #pragma warning(push, 1)
61 #endif
62 #include <windows.h>
63 #if defined _MSC_VER
64 #pragma warning(pop)
65 #endif
67 //--------------------------------------------------------------
68 // namesapces
69 //--------------------------------------------------------------
71 using namespace ::rtl ;
72 using namespace ::cppu ;
73 using namespace ::com::sun::star::uno ;
74 using namespace ::com::sun::star::lang ;
75 using namespace std ;
76 using namespace com::sun::star::system;
78 //--------------------------------------------------------------
79 // defines
80 //--------------------------------------------------------------
82 #define RDB_SYSPATH "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\applicat.rdb"
84 //--------------------------------------------------------------
85 // global variables
86 //--------------------------------------------------------------
88 Reference< XMultiServiceFactory > g_xFactory;
91 //--------------------------------------------------------------
92 // main
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 //-------------------------------------------------
103 if ( nArgc < 4 )
104 return 0;
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");
114 return(-1);
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" );
129 return(-1);
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 //--------------------------------------------------
150 // shutdown
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();
164 g_xFactory.clear();
165 g_xFactory = Reference< XMultiServiceFactory >();
167 printf("Test successful\n");
169 return 0;