xref: /AOO41X/main/setup_native/source/win32/customactions/quickstarter/shutdown_quickstart.cxx (revision 32b1fd08cf0851da51c0ed68f50bc63c4ee660e0)
1*32b1fd08SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*32b1fd08SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*32b1fd08SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*32b1fd08SAndrew Rist  * distributed with this work for additional information
6*32b1fd08SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*32b1fd08SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*32b1fd08SAndrew Rist  * "License"); you may not use this file except in compliance
9*32b1fd08SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*32b1fd08SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*32b1fd08SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*32b1fd08SAndrew Rist  * software distributed under the License is distributed on an
15*32b1fd08SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*32b1fd08SAndrew Rist  * KIND, either express or implied.  See the License for the
17*32b1fd08SAndrew Rist  * specific language governing permissions and limitations
18*32b1fd08SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*32b1fd08SAndrew Rist  *************************************************************/
21*32b1fd08SAndrew Rist 
22*32b1fd08SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "quickstarter.hxx"
25cdf0e10cSrcweir #include <setup_native/qswin32.h>
26cdf0e10cSrcweir 
EnumWindowsProc(HWND hWnd,LPARAM lParam)27cdf0e10cSrcweir static BOOL CALLBACK EnumWindowsProc( HWND hWnd, LPARAM lParam )
28cdf0e10cSrcweir {
29cdf0e10cSrcweir 	MSIHANDLE	hMSI = static_cast< MSIHANDLE >( lParam );
30cdf0e10cSrcweir 	CHAR	szClassName[sizeof(QUICKSTART_CLASSNAMEA) + 1];
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 	int	nCharsCopied = GetClassName( hWnd, szClassName, sizeof( szClassName ) );
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 	if ( nCharsCopied && !stricmp( QUICKSTART_CLASSNAMEA, szClassName ) )
35cdf0e10cSrcweir 	{
36cdf0e10cSrcweir 		DWORD	dwProcessId;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 		if ( GetWindowThreadProcessId( hWnd, &dwProcessId ) )
39cdf0e10cSrcweir 		{
40cdf0e10cSrcweir 			std::string	sImagePath = GetProcessImagePath( dwProcessId );
41cdf0e10cSrcweir 			std::string	sOfficeImageDir = GetOfficeInstallationPath( hMSI ) + "program\\";
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 			if ( !strnicmp( sImagePath.c_str(), sOfficeImageDir.c_str(), sOfficeImageDir.length() ) )
44cdf0e10cSrcweir 			{
45cdf0e10cSrcweir 				UINT	uMsgShutdownQuickstart = RegisterWindowMessageA( SHUTDOWN_QUICKSTART_MESSAGEA );
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 				if ( uMsgShutdownQuickstart )
48cdf0e10cSrcweir 					SendMessageA( hWnd, uMsgShutdownQuickstart, 0, 0 );
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 				HANDLE	hProcess = OpenProcess( SYNCHRONIZE, FALSE, dwProcessId );
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 				if ( hProcess )
54cdf0e10cSrcweir 				{
55cdf0e10cSrcweir 					WaitForSingleObject( hProcess, 30000 ); // Wait at most 30 seconds for process to terminate
56cdf0e10cSrcweir 					CloseHandle( hProcess );
57cdf0e10cSrcweir 				}
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 				return FALSE;
60cdf0e10cSrcweir 			}
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 		}
63cdf0e10cSrcweir 	}
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	return TRUE;
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 
ShutDownQuickstarter(MSIHANDLE hMSI)69cdf0e10cSrcweir extern "C" UINT __stdcall ShutDownQuickstarter( MSIHANDLE hMSI )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir 	EnumWindows( EnumWindowsProc, hMSI );
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     return ERROR_SUCCESS;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76