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
10*32b1fd08SAndrew Rist  *
11*32b1fd08SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*32b1fd08SAndrew Rist  *
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.
19*32b1fd08SAndrew Rist  *
20*32b1fd08SAndrew Rist  *************************************************************/
21*32b1fd08SAndrew Rist 
22*32b1fd08SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir /*
25cdf0e10cSrcweir 
26cdf0e10cSrcweir */
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #define UNICODE
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #ifdef _MSC_VER
32cdf0e10cSrcweir #pragma warning(push, 1) /* disable warnings within system headers */
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir #define WIN32_LEAN_AND_MEAN
35cdf0e10cSrcweir #include <windows.h>
36cdf0e10cSrcweir #include <msiquery.h>
37cdf0e10cSrcweir #ifdef _MSC_VER
38cdf0e10cSrcweir #pragma warning(pop)
39cdf0e10cSrcweir #endif
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <malloc.h>
42cdf0e10cSrcweir //#include <string>
43cdf0e10cSrcweir //#include <map>
44cdf0e10cSrcweir #include <strsafe.h>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // 10.11.2009 tkr: MinGW doesn't know anything about RegDeleteKeyExW if WINVER < 0x0502.
47cdf0e10cSrcweir extern "C" {
48cdf0e10cSrcweir WINADVAPI LONG WINAPI RegDeleteKeyExW(HKEY,LPCWSTR,REGSAM,DWORD);
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
51cdf0e10cSrcweir // 06.11.2009 tkr: to provide windows xp as build systems for mingw we need to define KEY_WOW64_64KEY
52cdf0e10cSrcweir // in mingw 3.13 KEY_WOW64_64KEY isn't available < Win2003 systems.
53cdf0e10cSrcweir // Also defined in setup_native\source\win32\customactions\reg64\reg64.cxx,source\win32\customactions\shellextensions\shellextensions.cxx and
54cdf0e10cSrcweir // extensions\source\activex\main\so_activex.cpp
55cdf0e10cSrcweir 
56cdf0e10cSrcweir #ifndef KEY_WOW64_64KEY
57cdf0e10cSrcweir 	#define KEY_WOW64_64KEY	(0x0100)
58cdf0e10cSrcweir #endif
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir #define TABLE_NAME L"Reg64"
62cdf0e10cSrcweir #define INSTALLLOCATION L"[INSTALLLOCATION]"
63cdf0e10cSrcweir 
64cdf0e10cSrcweir bool isInstall4AllUsers;
65cdf0e10cSrcweir wchar_t * sBasisInstallLocation;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 
68cdf0e10cSrcweir enum OPERATION {
69cdf0e10cSrcweir 	SET,
70cdf0e10cSrcweir 	REMOVE
71cdf0e10cSrcweir };
72cdf0e10cSrcweir 
73cdf0e10cSrcweir #ifdef DEBUG
74cdf0e10cSrcweir inline void OutputDebugStringFormat( const wchar_t* pFormat, ... )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir 	wchar_t    buffer[1024];
77cdf0e10cSrcweir 	va_list args;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	va_start( args, pFormat );
80cdf0e10cSrcweir 	StringCchVPrintf( buffer, sizeof(buffer), pFormat, args );
81cdf0e10cSrcweir 	OutputDebugString( buffer );
82cdf0e10cSrcweir }
83cdf0e10cSrcweir #else
84cdf0e10cSrcweir static inline void OutputDebugStringFormat( const wchar_t*, ... )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir }
87cdf0e10cSrcweir #endif
88cdf0e10cSrcweir 
89cdf0e10cSrcweir bool WriteRegistry( MSIHANDLE & hMSI, OPERATION op, const wchar_t* componentName)
90cdf0e10cSrcweir {
91cdf0e10cSrcweir 	INSTALLSTATE current_state;
92cdf0e10cSrcweir     INSTALLSTATE comp_state;
93cdf0e10cSrcweir 	UINT ret = MsiGetComponentState( hMSI, componentName, &current_state, &comp_state );
94cdf0e10cSrcweir 	if ( ERROR_SUCCESS == ret )
95cdf0e10cSrcweir 	{
96cdf0e10cSrcweir 		if (current_state == INSTALLSTATE_ABSENT)
97cdf0e10cSrcweir 			OutputDebugStringFormat(L"WriteRegistry - current_state: INSTALLSTATE_ABSENT");
98cdf0e10cSrcweir 		else if (current_state == INSTALLSTATE_DEFAULT)
99cdf0e10cSrcweir 			OutputDebugStringFormat(L"WriteRegistry - current_state: INSTALLSTATE_DEFAULT");
100cdf0e10cSrcweir 		else if (current_state == INSTALLSTATE_LOCAL)
101cdf0e10cSrcweir 			OutputDebugStringFormat(L"WriteRegistry - current_state: INSTALLSTATE_LOCAL");
102cdf0e10cSrcweir 		else if (current_state == INSTALLSTATE_REMOVED)
103cdf0e10cSrcweir 			OutputDebugStringFormat(L"WriteRegistry - current_state: INSTALLSTATE_REMOVED");
104cdf0e10cSrcweir 		else if (current_state == INSTALLSTATE_SOURCE)
105cdf0e10cSrcweir 			OutputDebugStringFormat(L"WriteRegistry - current_state: INSTALLSTATE_SOURCE");
106cdf0e10cSrcweir 		else if (current_state == INSTALLSTATE_UNKNOWN)
107cdf0e10cSrcweir 			OutputDebugStringFormat(L"WriteRegistry - current_state: INSTALLSTATE_UNKNOWN");
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 		if (comp_state == INSTALLSTATE_ABSENT)
110cdf0e10cSrcweir 			OutputDebugStringFormat(L"WriteRegistry - comp_state: INSTALLSTATE_ABSENT");
111cdf0e10cSrcweir 		else if (comp_state == INSTALLSTATE_DEFAULT)
112cdf0e10cSrcweir 			OutputDebugStringFormat(L"WriteRegistry - comp_state: INSTALLSTATE_DEFAULT");
113cdf0e10cSrcweir 		else if (comp_state == INSTALLSTATE_LOCAL)
114cdf0e10cSrcweir 			OutputDebugStringFormat(L"WriteRegistry - comp_state: INSTALLSTATE_LOCAL");
115cdf0e10cSrcweir 		else if (comp_state == INSTALLSTATE_REMOVED)
116cdf0e10cSrcweir 			OutputDebugStringFormat(L"WriteRegistry - comp_state: INSTALLSTATE_REMOVED");
117cdf0e10cSrcweir 		else if (comp_state == INSTALLSTATE_SOURCE)
118cdf0e10cSrcweir 			OutputDebugStringFormat(L"WriteRegistry - comp_state: INSTALLSTATE_SOURCE");
119cdf0e10cSrcweir 		else if (comp_state == INSTALLSTATE_UNKNOWN)
120cdf0e10cSrcweir 			OutputDebugStringFormat(L"WriteRegistry - comp_state: INSTALLSTATE_UNKNOWN");
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 		switch (op)
123cdf0e10cSrcweir 		{
124cdf0e10cSrcweir 			case SET :
125cdf0e10cSrcweir 				if ( comp_state == INSTALLSTATE_LOCAL || ( current_state == INSTALLSTATE_LOCAL && comp_state == INSTALLSTATE_UNKNOWN ) )
126cdf0e10cSrcweir 				{
127cdf0e10cSrcweir 					return true;
128cdf0e10cSrcweir 				}
129cdf0e10cSrcweir 				break;
130cdf0e10cSrcweir 			case REMOVE:
131cdf0e10cSrcweir 				OutputDebugStringFormat(L"WriteRegistry - Remove\n" );
132cdf0e10cSrcweir 				if ( current_state == INSTALLSTATE_LOCAL && (comp_state == INSTALLSTATE_ABSENT || comp_state == INSTALLSTATE_REMOVED) )
133cdf0e10cSrcweir 				{
134cdf0e10cSrcweir 					OutputDebugStringFormat(L"WriteRegistry - To be removed\n" );
135cdf0e10cSrcweir 					return true;
136cdf0e10cSrcweir 				}
137cdf0e10cSrcweir 		}
138cdf0e10cSrcweir 	} else
139cdf0e10cSrcweir 	{
140cdf0e10cSrcweir 		if (ERROR_INVALID_HANDLE == ret) OutputDebugStringFormat(L"WriteRegistry - Invalid handle");
141cdf0e10cSrcweir 		if (ERROR_UNKNOWN_FEATURE  == ret) OutputDebugStringFormat(L"WriteRegistry - Unknown feature");
142cdf0e10cSrcweir 	}
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	return false;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
147cdf0e10cSrcweir BOOL UnicodeEquals( wchar_t* pStr1, wchar_t* pStr2 )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir 	if ( pStr1 == NULL && pStr2 == NULL )
150cdf0e10cSrcweir 		return TRUE;
151cdf0e10cSrcweir 	else if ( pStr1 == NULL || pStr2 == NULL )
152cdf0e10cSrcweir 		return FALSE;
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	while( *pStr1 == *pStr2 && *pStr1 && *pStr2 )
155cdf0e10cSrcweir 		pStr1++, pStr2++;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	return ( *pStr1 == 0 && *pStr2 == 0 );
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir BOOL GetMsiProp( MSIHANDLE hMSI, const wchar_t* pPropName, wchar_t** ppValue )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir 	OutputDebugStringFormat(L"GetMsiProp - START\n" );
163cdf0e10cSrcweir     DWORD sz = 0;
164cdf0e10cSrcweir 	UINT ret = MsiGetProperty( hMSI, pPropName, L"", &sz );
165cdf0e10cSrcweir    	if ( ret == ERROR_MORE_DATA )
166cdf0e10cSrcweir    	{
167cdf0e10cSrcweir        	sz++;
168cdf0e10cSrcweir        	DWORD nbytes = sz * sizeof( wchar_t );
169cdf0e10cSrcweir        	wchar_t* buff = reinterpret_cast<wchar_t*>( malloc( nbytes ) );
170cdf0e10cSrcweir        	ZeroMemory( buff, nbytes );
171cdf0e10cSrcweir        	MsiGetProperty( hMSI, pPropName, buff, &sz );
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 		OutputDebugStringFormat(L"GetMsiProp - Value" );
174cdf0e10cSrcweir 		OutputDebugStringFormat( buff );
175cdf0e10cSrcweir    		*ppValue = buff;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 		return TRUE;
178cdf0e10cSrcweir 	} else if (ret  == ERROR_INVALID_HANDLE)
179cdf0e10cSrcweir 	{
180cdf0e10cSrcweir 		OutputDebugStringFormat(L"GetMsiProp - ERROR_INVALID_HANDLE" );
181cdf0e10cSrcweir 	} else if (ret == ERROR_INVALID_PARAMETER)
182cdf0e10cSrcweir 	{
183cdf0e10cSrcweir 		OutputDebugStringFormat(L"GetMsiProp - ERROR_INVALID_PARAMETER" );
184cdf0e10cSrcweir 	} else if (ret == ERROR_SUCCESS)
185cdf0e10cSrcweir 	{
186cdf0e10cSrcweir 		OutputDebugStringFormat(L"GetMsiProp - ERROR_SUCCESS" );
187cdf0e10cSrcweir 	}
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 	OutputDebugStringFormat(L"GetMsiProp - ENDE\n" );
191cdf0e10cSrcweir 	return FALSE;
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir bool IsInstallForAllUsers( MSIHANDLE hMSI )
195cdf0e10cSrcweir {
196cdf0e10cSrcweir 	OutputDebugStringFormat(L"IsInstallForAllUsers - START\n" );
197cdf0e10cSrcweir     bool bResult = FALSE;
198cdf0e10cSrcweir     wchar_t* pVal = NULL;
199cdf0e10cSrcweir     if ( GetMsiProp( hMSI, L"ALLUSERS", &pVal ) && pVal )
200cdf0e10cSrcweir 	{
201cdf0e10cSrcweir     	bResult = UnicodeEquals( pVal , L"1" );
202cdf0e10cSrcweir 		free( pVal );
203cdf0e10cSrcweir 	}
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 	OutputDebugStringFormat(L"IsInstallForAllUsers - ENDE\n" );
206cdf0e10cSrcweir 	return bResult;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir wchar_t* GetBasisInstallLocation( MSIHANDLE hMSI )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir 	OutputDebugStringFormat(L"GetBasisInstallLocation - START\n" );
212cdf0e10cSrcweir     bool bResult = FALSE;
213cdf0e10cSrcweir     wchar_t* pVal = NULL;
214cdf0e10cSrcweir     GetMsiProp( hMSI, L"INSTALLLOCATION", &pVal);
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     OutputDebugStringFormat(L"GetBasisInstallLocation - ENDE\n" );
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     return pVal;
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 
222cdf0e10cSrcweir bool QueryReg64Table(MSIHANDLE& rhDatabase, MSIHANDLE& rhView)
223cdf0e10cSrcweir {
224cdf0e10cSrcweir 	OutputDebugStringFormat(L"QueryReg64Table - START\n" );
225cdf0e10cSrcweir 	int const arraysize = 400;
226cdf0e10cSrcweir 	wchar_t szSelect[arraysize];
227cdf0e10cSrcweir 	StringCbPrintfW(szSelect, arraysize * sizeof(wchar_t), L"SELECT * FROM %s",TABLE_NAME);
228cdf0e10cSrcweir 	OutputDebugStringFormat( szSelect );
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 	UINT ret = MsiDatabaseOpenView(rhDatabase,szSelect,&rhView);
231cdf0e10cSrcweir 	if (ret != ERROR_SUCCESS)
232cdf0e10cSrcweir 	{
233cdf0e10cSrcweir 		if ( ret == ERROR_BAD_QUERY_SYNTAX)
234cdf0e10cSrcweir 			OutputDebugStringFormat(L"QueryReg64Table - MsiDatabaseOpenView - FAILED - ERROR_BAD_QUERY_SYNTAX\n" );
235cdf0e10cSrcweir 		if ( ret == ERROR_INVALID_HANDLE)
236cdf0e10cSrcweir 			OutputDebugStringFormat(L"QueryReg64Table - MsiDatabaseOpenView - FAILED - ERROR_INVALID_HANDLE\n" );
237cdf0e10cSrcweir 		return false;
238cdf0e10cSrcweir 	}
239cdf0e10cSrcweir 	// execute query - not a parameter query so second parameter is NULL.
240cdf0e10cSrcweir 	if (MsiViewExecute(rhView,NULL) != ERROR_SUCCESS)
241cdf0e10cSrcweir 	{
242cdf0e10cSrcweir 		OutputDebugStringFormat(L"QueryReg64Table - MsiViewExecute - FAILED\n" );
243cdf0e10cSrcweir 		return false;
244cdf0e10cSrcweir 	}
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 	OutputDebugStringFormat(L"QueryReg64Table - ENDE\n" );
247cdf0e10cSrcweir 	return true;
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir //---------------------------------------
251cdf0e10cSrcweir bool DeleteRegistryKey(HKEY RootKey, const wchar_t* KeyName)
252cdf0e10cSrcweir {
253cdf0e10cSrcweir 	int rc = RegDeleteKeyExW(
254cdf0e10cSrcweir 		RootKey, KeyName, KEY_WOW64_64KEY, 0);
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 	return (ERROR_SUCCESS == rc);
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 
262cdf0e10cSrcweir //---------------------------------------
263cdf0e10cSrcweir //
264cdf0e10cSrcweir //---------------------------------------
265cdf0e10cSrcweir 
266cdf0e10cSrcweir bool SetRegistryKey(HKEY RootKey, const wchar_t* KeyName, const wchar_t* ValueName, const wchar_t* Value)
267cdf0e10cSrcweir {
268cdf0e10cSrcweir 	HKEY hSubKey;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 	// open or create the desired key
271cdf0e10cSrcweir 	int rc = RegCreateKeyEx(
272cdf0e10cSrcweir 		RootKey, KeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_WOW64_64KEY, 0, &hSubKey, 0);
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 	if (ERROR_SUCCESS == rc)
275cdf0e10cSrcweir 	{
276cdf0e10cSrcweir 		OutputDebugStringFormat(L"SetRegistryKey - Created\n" );
277cdf0e10cSrcweir 		rc = RegSetValueEx(
278cdf0e10cSrcweir 			hSubKey, ValueName, 0, REG_SZ, reinterpret_cast<const BYTE*>(Value), (wcslen(Value) + 1) * sizeof(wchar_t));
279cdf0e10cSrcweir 
280cdf0e10cSrcweir 		RegCloseKey(hSubKey);
281cdf0e10cSrcweir 	} else {
282cdf0e10cSrcweir 		OutputDebugStringFormat(L"SetRegistryKey - FAILED\n" );
283cdf0e10cSrcweir 	}
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 
286cdf0e10cSrcweir 	return (ERROR_SUCCESS == rc);
287cdf0e10cSrcweir }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir bool DoRegEntries( MSIHANDLE& rhMSI, OPERATION op, MSIHANDLE& rhView)
290cdf0e10cSrcweir {
291cdf0e10cSrcweir 	OutputDebugStringFormat(L"DoRegEntries - START\n" );
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 	MSIHANDLE hRecord;
294cdf0e10cSrcweir 
295cdf0e10cSrcweir 	long lRoot;
296cdf0e10cSrcweir 	wchar_t  szKey[255];
297cdf0e10cSrcweir 	wchar_t  szName[255];
298cdf0e10cSrcweir 	wchar_t  szValue[1024];
299cdf0e10cSrcweir 	wchar_t  szComponent[255];
300cdf0e10cSrcweir 
301cdf0e10cSrcweir 	/// read records until there are no more records
302cdf0e10cSrcweir 	while (MsiViewFetch(rhView,&hRecord) == ERROR_SUCCESS)
303cdf0e10cSrcweir 	{
304cdf0e10cSrcweir 		DWORD	 dwKey = 255;
305cdf0e10cSrcweir 		DWORD	 dwName = 255;
306cdf0e10cSrcweir 		DWORD	 dwValue = 1024;
307cdf0e10cSrcweir 		DWORD	 dwComponent = 255;
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 		szKey[0] = '\0';
310cdf0e10cSrcweir 		szName[0] = '\0';
311cdf0e10cSrcweir 		szValue[0] = '\0';
312cdf0e10cSrcweir 		szComponent[0] = '\0';
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 		lRoot = MsiRecordGetInteger(hRecord,2);
315cdf0e10cSrcweir 		MsiRecordGetString(hRecord,3,szKey,&dwKey);
316cdf0e10cSrcweir 
317cdf0e10cSrcweir 		if (!MsiRecordIsNull(hRecord, 4))
318cdf0e10cSrcweir 			MsiRecordGetString(hRecord,4,szName,&dwName);
319cdf0e10cSrcweir 
320cdf0e10cSrcweir 		if (!MsiRecordIsNull(hRecord, 5))
321cdf0e10cSrcweir 		{
322cdf0e10cSrcweir 			MsiRecordGetString(hRecord,5,szValue,&dwValue);
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 
325cdf0e10cSrcweir 
326cdf0e10cSrcweir 			wchar_t* nPos = wcsstr(szValue , INSTALLLOCATION);
327cdf0e10cSrcweir 			if ( NULL != nPos)
328cdf0e10cSrcweir 			{
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 				DWORD nPrefixSize = nPos - szValue;
331cdf0e10cSrcweir 
332cdf0e10cSrcweir 				DWORD nPropSize = wcslen(sBasisInstallLocation);
333cdf0e10cSrcweir 				DWORD nPostfixSize = dwValue - wcslen( INSTALLLOCATION );
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 				DWORD nNewValueBytes = (nPropSize + nPostfixSize + 1) * sizeof( wchar_t );
336cdf0e10cSrcweir        			wchar_t* newValue = reinterpret_cast<wchar_t*>( malloc( nNewValueBytes ) );
337cdf0e10cSrcweir        			ZeroMemory( newValue, nNewValueBytes );
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 				// prefix
340cdf0e10cSrcweir 				wcsncpy(newValue, szValue, nPrefixSize);
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 				// basis location
343cdf0e10cSrcweir 				wcsncat(newValue, sBasisInstallLocation, nPropSize * sizeof( wchar_t ));
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 				// postfix
346cdf0e10cSrcweir 				wcsncat(newValue, nPos + ( wcslen( INSTALLLOCATION ) ), nPropSize * sizeof( wchar_t ));
347cdf0e10cSrcweir 
348cdf0e10cSrcweir 				wcsncpy(szValue, newValue, nNewValueBytes <=1024? nNewValueBytes: 1024);
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 				free(newValue);
351cdf0e10cSrcweir 			}
352cdf0e10cSrcweir 
353cdf0e10cSrcweir 		}
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 		MsiRecordGetString(hRecord,6,szComponent,&dwComponent);
357cdf0e10cSrcweir 
358cdf0e10cSrcweir 		OutputDebugStringFormat(L"****** DoRegEntries *******" );
359cdf0e10cSrcweir 		OutputDebugStringFormat(L"Root:" );
360cdf0e10cSrcweir 		HKEY key = HKEY_CURRENT_USER;
361cdf0e10cSrcweir 		switch (lRoot)
362cdf0e10cSrcweir 		{
363cdf0e10cSrcweir 			case(-1):
364cdf0e10cSrcweir 					if (isInstall4AllUsers)
365cdf0e10cSrcweir 					{
366cdf0e10cSrcweir 						key = HKEY_LOCAL_MACHINE;
367cdf0e10cSrcweir 						OutputDebugStringFormat(L"HKEY_LOCAL_MACHINE" );
368cdf0e10cSrcweir 					}
369cdf0e10cSrcweir 					else
370cdf0e10cSrcweir 					{
371cdf0e10cSrcweir 						key = HKEY_CURRENT_USER;
372cdf0e10cSrcweir 						OutputDebugStringFormat(L"HKEY_CURRENT_USER" );
373cdf0e10cSrcweir 					}
374cdf0e10cSrcweir 				break;
375cdf0e10cSrcweir 			case(0):
376cdf0e10cSrcweir 					key = HKEY_CLASSES_ROOT;
377cdf0e10cSrcweir 					OutputDebugStringFormat(L"HKEY_CLASSES_ROOT" );
378cdf0e10cSrcweir 				break;
379cdf0e10cSrcweir 			case(1):
380cdf0e10cSrcweir 					key = HKEY_CURRENT_USER;
381cdf0e10cSrcweir 					OutputDebugStringFormat(L"HKEY_CURRENT_USER" );
382cdf0e10cSrcweir 				break;
383cdf0e10cSrcweir 			case(2):
384cdf0e10cSrcweir 					key = HKEY_LOCAL_MACHINE;
385cdf0e10cSrcweir 					OutputDebugStringFormat(L"HKEY_LOCAL_MACHINE" );
386cdf0e10cSrcweir 				break;
387cdf0e10cSrcweir 			case(3):
388cdf0e10cSrcweir 					key = HKEY_USERS;
389cdf0e10cSrcweir 					OutputDebugStringFormat(L"HKEY_USERS" );
390cdf0e10cSrcweir 				break;
391cdf0e10cSrcweir 			default:
392cdf0e10cSrcweir 					OutputDebugStringFormat(L"Unknown Root!" );
393cdf0e10cSrcweir 				break;
394cdf0e10cSrcweir 		}
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 		OutputDebugStringFormat(L"Key:");
397cdf0e10cSrcweir 		OutputDebugStringFormat( szKey );
398cdf0e10cSrcweir 		OutputDebugStringFormat(L"Name:");
399cdf0e10cSrcweir 		OutputDebugStringFormat( szName );
400cdf0e10cSrcweir 		OutputDebugStringFormat(L"Value:");
401cdf0e10cSrcweir 		OutputDebugStringFormat( szValue);
402cdf0e10cSrcweir 		OutputDebugStringFormat(L"Component:");
403cdf0e10cSrcweir 		OutputDebugStringFormat( szComponent );
404cdf0e10cSrcweir 		OutputDebugStringFormat(L"*******************" );
405cdf0e10cSrcweir 		switch (op)
406cdf0e10cSrcweir 		{
407cdf0e10cSrcweir 			case SET:
408cdf0e10cSrcweir 
409cdf0e10cSrcweir 					if (WriteRegistry(rhMSI, SET, szComponent))
410cdf0e10cSrcweir 					{
411cdf0e10cSrcweir 						OutputDebugStringFormat(L"DoRegEntries - Write\n" );
412cdf0e10cSrcweir 						SetRegistryKey(key, szKey, szName, szValue);
413cdf0e10cSrcweir 					}
414cdf0e10cSrcweir 				break;
415cdf0e10cSrcweir 			case REMOVE:
416cdf0e10cSrcweir 					OutputDebugStringFormat(L"DoRegEntries - PreRemove\n" );
417cdf0e10cSrcweir 					if (WriteRegistry(rhMSI, REMOVE, szComponent))
418cdf0e10cSrcweir 					{
419cdf0e10cSrcweir 						OutputDebugStringFormat(L"DoRegEntries - Remove\n" );
420cdf0e10cSrcweir 						DeleteRegistryKey(key, szKey);
421cdf0e10cSrcweir 					}
422cdf0e10cSrcweir 				break;
423cdf0e10cSrcweir 		}
424cdf0e10cSrcweir 	}
425cdf0e10cSrcweir 
426cdf0e10cSrcweir 	MsiCloseHandle(rhView);
427cdf0e10cSrcweir 
428cdf0e10cSrcweir 
429cdf0e10cSrcweir 	OutputDebugStringFormat(L"DoRegEntries - ENDE\n" );
430cdf0e10cSrcweir 
431cdf0e10cSrcweir 	return true;
432cdf0e10cSrcweir }
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 
435cdf0e10cSrcweir bool Reg64(MSIHANDLE& rhMSI, OPERATION op)
436cdf0e10cSrcweir {
437cdf0e10cSrcweir 	isInstall4AllUsers = IsInstallForAllUsers(rhMSI);
438cdf0e10cSrcweir 	sBasisInstallLocation = GetBasisInstallLocation(rhMSI);
439cdf0e10cSrcweir 
440cdf0e10cSrcweir 	if (NULL == sBasisInstallLocation)
441cdf0e10cSrcweir 	{
442cdf0e10cSrcweir 		OutputDebugStringFormat(L"BASISINSTALLLOCATION is NULL\n" );
443cdf0e10cSrcweir 		return false;
444cdf0e10cSrcweir 	}
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 	MSIHANDLE hView;
447cdf0e10cSrcweir 	MSIHANDLE hDatabase = MsiGetActiveDatabase(rhMSI);
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 	QueryReg64Table(hDatabase, hView);
450cdf0e10cSrcweir 	OutputDebugStringFormat(L"Do something\n" );
451cdf0e10cSrcweir 	DoRegEntries( rhMSI, op, hView);
452cdf0e10cSrcweir 	OutputDebugStringFormat(L"Something done\n" );
453cdf0e10cSrcweir 
454cdf0e10cSrcweir 	MsiCloseHandle(hView);
455cdf0e10cSrcweir 	MsiCloseHandle(hDatabase);
456cdf0e10cSrcweir 	free(sBasisInstallLocation);
457cdf0e10cSrcweir 
458cdf0e10cSrcweir 	return true;
459cdf0e10cSrcweir }
460cdf0e10cSrcweir 
461cdf0e10cSrcweir extern "C" UINT __stdcall InstallReg64(MSIHANDLE hMSI)
462cdf0e10cSrcweir {
463cdf0e10cSrcweir 	OutputDebugStringFormat(L"InstallReg64\n" );
464cdf0e10cSrcweir 	Reg64(hMSI, SET);
465cdf0e10cSrcweir 	return ERROR_SUCCESS;
466cdf0e10cSrcweir }
467cdf0e10cSrcweir 
468cdf0e10cSrcweir extern "C" UINT __stdcall DeinstallReg64(MSIHANDLE hMSI)
469cdf0e10cSrcweir {
470cdf0e10cSrcweir 	OutputDebugStringFormat(L"DeinstallReg64\n" );
471cdf0e10cSrcweir 	Reg64(hMSI, REMOVE);
472cdf0e10cSrcweir 	return ERROR_SUCCESS;
473cdf0e10cSrcweir }