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