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