1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_shell.hxx"
30 
31 
32 //-----------------------------------------------------------
33 //	interface includes
34 //-----------------------------------------------------------
35 #include <com/sun/star/lang/XComponent.hpp>
36 #include <com/sun/star/registry/XSimpleRegistry.hpp>
37 
38 #ifndef _COM_SUN_STAR_SYS_SHELL_XSYSTEMSHELLEXECUTE_HPP_
39 #include <com/sun/star/system/XSystemShellExecute.hpp>
40 #endif
41 #include <cppuhelper/servicefactory.hxx>
42 
43 
44 #include <osl/file.hxx>
45 
46 //--------------------------------------------------------------
47 //	other includes
48 //--------------------------------------------------------------
49 #include <cppuhelper/servicefactory.hxx>
50 #include <rtl/ustring.hxx>
51 #include <sal/types.h>
52 #include <osl/diagnose.h>
53 
54 #include <stdio.h>
55 
56 #if defined _MSC_VER
57 #pragma warning(push, 1)
58 #endif
59 #include <windows.h>
60 #if defined _MSC_VER
61 #pragma warning(pop)
62 #endif
63 
64 //--------------------------------------------------------------
65 //	namesapces
66 //--------------------------------------------------------------
67 
68 using namespace	::rtl					;
69 using namespace	::cppu					;
70 using namespace	::com::sun::star::uno	;
71 using namespace	::com::sun::star::lang	;
72 using namespace std						;
73 using namespace com::sun::star::system;
74 
75 //--------------------------------------------------------------
76 //	defines
77 //--------------------------------------------------------------
78 
79 #define RDB_SYSPATH "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\applicat.rdb"
80 
81 //--------------------------------------------------------------
82 //	global variables
83 //--------------------------------------------------------------
84 
85 Reference< XMultiServiceFactory >	g_xFactory;
86 
87 
88 //--------------------------------------------------------------
89 //	main
90 //--------------------------------------------------------------
91 
92 
93 // int SAL_CALL main(int nArgc, char* Argv[], char* Env[]	)
94 int SAL_CALL main(int nArgc, char* Argv[], char*	)
95 {
96 	//-------------------------------------------------
97 	// get the global service-manager
98 	//-------------------------------------------------
99 
100     if ( nArgc < 4 )
101         return 0;
102 
103 	// Get global factory for uno services.
104 	OUString rdbName = OUString( RTL_CONSTASCII_USTRINGPARAM( RDB_SYSPATH ) );
105 	Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( rdbName ) );
106 
107 	// Print a message if an error occured.
108 	if ( g_xFactory.is() == sal_False )
109 	{
110 		OSL_ENSURE(sal_False, "Can't create RegistryServiceFactory");
111 		return(-1);
112 	}
113 
114 	printf("Creating RegistryServiceFactory successful\n");
115 
116 	//-------------------------------------------------
117 	// try to get an Interface to a XFilePicker Service
118 	//-------------------------------------------------
119 
120 	Reference< XSystemShellExecute > xSysShExec(
121         g_xFactory->createInstance( OUString::createFromAscii( "com.sun.star.system.SystemShellExecute" ) ), UNO_QUERY );
122 
123 	if ( !xSysShExec.is() )
124 	{
125 		OSL_ENSURE( sal_False, "Error creating SystemShellExecute Service" );
126 		return(-1);
127 	}
128 
129     //"c:\\winnt\\notepad.exe"
130     OUString cmd = OUString::createFromAscii( Argv[1] );
131     OUString param = OUString::createFromAscii( Argv[2] ); //c:\\winnt\\iis5.log
132 
133     try
134     {
135         xSysShExec->execute( cmd, param, atoi( Argv[3] ) );
136     }
137     catch( SystemShellExecuteException&  )
138     {
139         OSL_ENSURE( sal_False, "Error executing system command" );
140     }
141     catch( IllegalArgumentException& )
142     {
143         OSL_ENSURE( sal_False, "Invalid parameter" );
144     }
145 
146 	//--------------------------------------------------
147 	// shutdown
148 	//--------------------------------------------------
149 
150 	// Cast factory to XComponent
151 	Reference< XComponent > xComponent( g_xFactory, UNO_QUERY );
152 
153 	// Print a message if an error occured.
154 	if ( xComponent.is() == sal_False )
155 	{
156 		OSL_ENSURE(sal_False, "Error shuting down");
157 	}
158 
159 	// Dispose and clear factory
160 	xComponent->dispose();
161 	g_xFactory.clear();
162 	g_xFactory = Reference< XMultiServiceFactory >();
163 
164 	printf("Test successful\n");
165 
166 	return 0;
167 }
168