1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_shell.hxx"
26 
27 
28 //-----------------------------------------------------------
29 //	interface includes
30 //-----------------------------------------------------------
31 #include <com/sun/star/lang/XComponent.hpp>
32 #include <com/sun/star/registry/XSimpleRegistry.hpp>
33 
34 #ifndef _COM_SUN_STAR_SYS_SHELL_XSYSTEMSHELLEXECUTE_HPP_
35 #include <com/sun/star/system/XSystemShellExecute.hpp>
36 #endif
37 #include <cppuhelper/servicefactory.hxx>
38 
39 
40 #include <osl/file.hxx>
41 
42 //--------------------------------------------------------------
43 //	other includes
44 //--------------------------------------------------------------
45 #include <cppuhelper/servicefactory.hxx>
46 #include <rtl/ustring.hxx>
47 #include <sal/types.h>
48 #include <osl/diagnose.h>
49 
50 #include <stdio.h>
51 
52 #if defined _MSC_VER
53 #pragma warning(push, 1)
54 #endif
55 #include <windows.h>
56 #if defined _MSC_VER
57 #pragma warning(pop)
58 #endif
59 
60 //--------------------------------------------------------------
61 //	namesapces
62 //--------------------------------------------------------------
63 
64 using namespace	::rtl					;
65 using namespace	::cppu					;
66 using namespace	::com::sun::star::uno	;
67 using namespace	::com::sun::star::lang	;
68 using namespace std						;
69 using namespace com::sun::star::system;
70 
71 //--------------------------------------------------------------
72 //	defines
73 //--------------------------------------------------------------
74 
75 #define RDB_SYSPATH "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\applicat.rdb"
76 
77 //--------------------------------------------------------------
78 //	global variables
79 //--------------------------------------------------------------
80 
81 Reference< XMultiServiceFactory >	g_xFactory;
82 
83 
84 //--------------------------------------------------------------
85 //	main
86 //--------------------------------------------------------------
87 
88 
89 // int SAL_CALL main(int nArgc, char* Argv[], char* Env[]	)
90 int SAL_CALL main(int nArgc, char* Argv[], char*	)
91 {
92 	//-------------------------------------------------
93 	// get the global service-manager
94 	//-------------------------------------------------
95 
96     if ( nArgc < 4 )
97         return 0;
98 
99 	// Get global factory for uno services.
100 	OUString rdbName = OUString( RTL_CONSTASCII_USTRINGPARAM( RDB_SYSPATH ) );
101 	Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( rdbName ) );
102 
103 	// Print a message if an error occured.
104 	if ( g_xFactory.is() == sal_False )
105 	{
106 		OSL_ENSURE(sal_False, "Can't create RegistryServiceFactory");
107 		return(-1);
108 	}
109 
110 	printf("Creating RegistryServiceFactory successful\n");
111 
112 	//-------------------------------------------------
113 	// try to get an Interface to a XFilePicker Service
114 	//-------------------------------------------------
115 
116 	Reference< XSystemShellExecute > xSysShExec(
117         g_xFactory->createInstance( OUString::createFromAscii( "com.sun.star.system.SystemShellExecute" ) ), UNO_QUERY );
118 
119 	if ( !xSysShExec.is() )
120 	{
121 		OSL_ENSURE( sal_False, "Error creating SystemShellExecute Service" );
122 		return(-1);
123 	}
124 
125     //"c:\\winnt\\notepad.exe"
126     OUString cmd = OUString::createFromAscii( Argv[1] );
127     OUString param = OUString::createFromAscii( Argv[2] ); //c:\\winnt\\iis5.log
128 
129     try
130     {
131         xSysShExec->execute( cmd, param, atoi( Argv[3] ) );
132     }
133     catch( SystemShellExecuteException&  )
134     {
135         OSL_ENSURE( sal_False, "Error executing system command" );
136     }
137     catch( IllegalArgumentException& )
138     {
139         OSL_ENSURE( sal_False, "Invalid parameter" );
140     }
141 
142 	//--------------------------------------------------
143 	// shutdown
144 	//--------------------------------------------------
145 
146 	// Cast factory to XComponent
147 	Reference< XComponent > xComponent( g_xFactory, UNO_QUERY );
148 
149 	// Print a message if an error occured.
150 	if ( xComponent.is() == sal_False )
151 	{
152 		OSL_ENSURE(sal_False, "Error shuting down");
153 	}
154 
155 	// Dispose and clear factory
156 	xComponent->dispose();
157 	g_xFactory.clear();
158 	g_xFactory = Reference< XMultiServiceFactory >();
159 
160 	printf("Test successful\n");
161 
162 	return 0;
163 }
164