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 #include <com/sun/star/system/XSystemShellExecute.hpp>
34 #include <cppuhelper/servicefactory.hxx>
35 
36 
37 #include <osl/file.hxx>
38 
39 //--------------------------------------------------------------
40 //	other includes
41 //--------------------------------------------------------------
42 #include <cppuhelper/servicefactory.hxx>
43 #include <rtl/ustring.hxx>
44 #include <sal/types.h>
45 #include <osl/diagnose.h>
46 
47 #include <stdio.h>
48 
49 #if defined _MSC_VER
50 #pragma warning(push, 1)
51 #endif
52 #include <windows.h>
53 #if defined _MSC_VER
54 #pragma warning(pop)
55 #endif
56 
57 //--------------------------------------------------------------
58 //	namesapces
59 //--------------------------------------------------------------
60 
61 using namespace	::rtl					;
62 using namespace	::cppu					;
63 using namespace	::com::sun::star::uno	;
64 using namespace	::com::sun::star::lang	;
65 using namespace std						;
66 using namespace com::sun::star::system;
67 
68 //--------------------------------------------------------------
69 //	defines
70 //--------------------------------------------------------------
71 
72 #define RDB_SYSPATH "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\applicat.rdb"
73 
74 //--------------------------------------------------------------
75 //	global variables
76 //--------------------------------------------------------------
77 
78 Reference< XMultiServiceFactory >	g_xFactory;
79 
80 
81 //--------------------------------------------------------------
82 //	main
83 //--------------------------------------------------------------
84 
85 
86 // int SAL_CALL main(int nArgc, char* Argv[], char* Env[]	)
main(int nArgc,char * Argv[],char *)87 int SAL_CALL main(int nArgc, char* Argv[], char*	)
88 {
89 	//-------------------------------------------------
90 	// get the global service-manager
91 	//-------------------------------------------------
92 
93     if ( nArgc < 4 )
94         return 0;
95 
96 	// Get global factory for uno services.
97 	OUString rdbName = OUString( RTL_CONSTASCII_USTRINGPARAM( RDB_SYSPATH ) );
98 	Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( rdbName ) );
99 
100 	// Print a message if an error occurred.
101 	if ( g_xFactory.is() == sal_False )
102 	{
103 		OSL_ENSURE(sal_False, "Can't create RegistryServiceFactory");
104 		return(-1);
105 	}
106 
107 	printf("Creating RegistryServiceFactory successful\n");
108 
109 	//-------------------------------------------------
110 	// try to get an Interface to a XFilePicker Service
111 	//-------------------------------------------------
112 
113 	Reference< XSystemShellExecute > xSysShExec(
114         g_xFactory->createInstance( OUString::createFromAscii( "com.sun.star.system.SystemShellExecute" ) ), UNO_QUERY );
115 
116 	if ( !xSysShExec.is() )
117 	{
118 		OSL_ENSURE( sal_False, "Error creating SystemShellExecute Service" );
119 		return(-1);
120 	}
121 
122     //"c:\\winnt\\notepad.exe"
123     OUString cmd = OUString::createFromAscii( Argv[1] );
124     OUString param = OUString::createFromAscii( Argv[2] ); //c:\\winnt\\iis5.log
125 
126     try
127     {
128         xSysShExec->execute( cmd, param, atoi( Argv[3] ) );
129     }
130     catch( SystemShellExecuteException&  )
131     {
132         OSL_ENSURE( sal_False, "Error executing system command" );
133     }
134     catch( IllegalArgumentException& )
135     {
136         OSL_ENSURE( sal_False, "Invalid parameter" );
137     }
138 
139 	//--------------------------------------------------
140 	// shutdown
141 	//--------------------------------------------------
142 
143 	// Cast factory to XComponent
144 	Reference< XComponent > xComponent( g_xFactory, UNO_QUERY );
145 
146 	// Print a message if an error occurred.
147 	if ( xComponent.is() == sal_False )
148 	{
149 		OSL_ENSURE(sal_False, "Error shuting down");
150 	}
151 
152 	// Dispose and clear factory
153 	xComponent->dispose();
154 	g_xFactory.clear();
155 	g_xFactory = Reference< XMultiServiceFactory >();
156 
157 	printf("Test successful\n");
158 
159 	return 0;
160 }
161