1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #define _WIN32_WINDOWS 0x0410 29*cdf0e10cSrcweir #ifdef _MSC_VER 30*cdf0e10cSrcweir #pragma warning(push, 1) /* disable warnings within system headers */ 31*cdf0e10cSrcweir #endif 32*cdf0e10cSrcweir #define WIN32_LEAN_AND_MEAN 33*cdf0e10cSrcweir #include <windows.h> 34*cdf0e10cSrcweir #include <msiquery.h> 35*cdf0e10cSrcweir #ifdef _MSC_VER 36*cdf0e10cSrcweir #pragma warning(pop) 37*cdf0e10cSrcweir #endif 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <malloc.h> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #ifdef UNICODE 42*cdf0e10cSrcweir #define _UNICODE 43*cdf0e10cSrcweir #define _tstring wstring 44*cdf0e10cSrcweir #else 45*cdf0e10cSrcweir #define _tstring string 46*cdf0e10cSrcweir #endif 47*cdf0e10cSrcweir #include <tchar.h> 48*cdf0e10cSrcweir #include <string> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir #include <io.h> 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir static std::_tstring GetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty ) 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir std::_tstring result; 55*cdf0e10cSrcweir TCHAR szDummy[1] = TEXT(""); 56*cdf0e10cSrcweir DWORD nChars = 0; 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir if ( MsiGetProperty( handle, sProperty.c_str(), szDummy, &nChars ) == ERROR_MORE_DATA ) 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir DWORD nBytes = ++nChars * sizeof(TCHAR); 61*cdf0e10cSrcweir LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes)); 62*cdf0e10cSrcweir ZeroMemory( buffer, nBytes ); 63*cdf0e10cSrcweir MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars); 64*cdf0e10cSrcweir result = buffer; 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir return result; 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir static BOOL ExecuteCommand( LPCTSTR lpCommand, BOOL bSync ) 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir BOOL fSuccess = FALSE; 74*cdf0e10cSrcweir STARTUPINFO si; 75*cdf0e10cSrcweir PROCESS_INFORMATION pi; 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir ZeroMemory( &si, sizeof(si) ); 78*cdf0e10cSrcweir si.cb = sizeof(si); 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir fSuccess = CreateProcess( 81*cdf0e10cSrcweir NULL, 82*cdf0e10cSrcweir (LPTSTR)lpCommand, 83*cdf0e10cSrcweir NULL, 84*cdf0e10cSrcweir NULL, 85*cdf0e10cSrcweir FALSE, 86*cdf0e10cSrcweir 0, 87*cdf0e10cSrcweir NULL, 88*cdf0e10cSrcweir NULL, 89*cdf0e10cSrcweir &si, 90*cdf0e10cSrcweir &pi 91*cdf0e10cSrcweir ); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir if ( fSuccess ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir if ( bSync ) 96*cdf0e10cSrcweir WaitForSingleObject( pi.hProcess, INFINITE ); 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir CloseHandle( pi.hProcess ); 99*cdf0e10cSrcweir CloseHandle( pi.hThread ); 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir return fSuccess; 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir extern "C" UINT __stdcall ExecutePostUninstallScript( MSIHANDLE handle ) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir TCHAR szValue[8192]; 108*cdf0e10cSrcweir DWORD nValueSize = sizeof(szValue); 109*cdf0e10cSrcweir HKEY hKey; 110*cdf0e10cSrcweir std::_tstring sInstDir; 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir std::_tstring sProductKey = GetMsiProperty( handle, TEXT("FINDPRODUCT") ); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir // MessageBox( NULL, sProductKey.c_str(), "Titel", MB_OK ); 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir if ( ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER, sProductKey.c_str(), &hKey ) ) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir if ( ERROR_SUCCESS == RegQueryValueEx( hKey, TEXT("INSTALLLOCATION"), NULL, NULL, (LPBYTE)szValue, &nValueSize ) ) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir sInstDir = szValue; 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir RegCloseKey( hKey ); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir else if ( ERROR_SUCCESS == RegOpenKey( HKEY_LOCAL_MACHINE, sProductKey.c_str(), &hKey ) ) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir if ( ERROR_SUCCESS == RegQueryValueEx( hKey, TEXT("INSTALLLOCATION"), NULL, NULL, (LPBYTE)szValue, &nValueSize ) ) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir sInstDir = szValue; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir RegCloseKey( hKey ); 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir else 133*cdf0e10cSrcweir return ERROR_SUCCESS; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir std::_tstring sInfFile = sInstDir + TEXT("program\\postuninstall.inf"); 136*cdf0e10cSrcweir std::_tstring sCommand = _T("RUNDLL32.EXE "); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir // MessageBox( NULL, sInfFile.c_str(), "Titel", MB_OK ); 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir if ( (LONG)GetVersion() < 0 ) 141*cdf0e10cSrcweir sCommand += _T("setupx.dll"); 142*cdf0e10cSrcweir else 143*cdf0e10cSrcweir sCommand += _T("setupapi.dll"); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir sCommand += _T(",InstallHinfSection PostUninstall 132 "); 146*cdf0e10cSrcweir sCommand += sInfFile; 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir if ( 0 == _taccess( sInfFile.c_str(), 2 ) ) 149*cdf0e10cSrcweir ExecuteCommand( sCommand.c_str(), TRUE ); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir DeleteFile( sInfFile.c_str() ); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir return ERROR_SUCCESS; 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156