1*32b1fd08SAndrew Rist /**************************************************************
2*32b1fd08SAndrew Rist *
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
22cdf0e10cSrcweir #define WIN32_LEAN_AND_MEAN
23cdf0e10cSrcweir
24cdf0e10cSrcweir #ifdef _MSC_VER
25cdf0e10cSrcweir #pragma warning(disable:4668 4917) // disable warnings for system headers
26cdf0e10cSrcweir #endif
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <windows.h>
29cdf0e10cSrcweir #include <windowsx.h>
30cdf0e10cSrcweir #include <shellapi.h>
31cdf0e10cSrcweir #include <shlobj.h>
32cdf0e10cSrcweir #include <tchar.h>
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include <stdio.h>
35cdf0e10cSrcweir
36cdf0e10cSrcweir #define elementsof(buf) (sizeof(buf) / sizeof(buf[0]))
37cdf0e10cSrcweir
38cdf0e10cSrcweir enum PathResult
39cdf0e10cSrcweir {
40cdf0e10cSrcweir PATHRESULT_OK,
41cdf0e10cSrcweir PATHRESULT_API_NOT_SUPPORTED,
42cdf0e10cSrcweir PATHRESULT_EXE_NOT_FOUND
43cdf0e10cSrcweir };
44cdf0e10cSrcweir
45cdf0e10cSrcweir const int MAXCMDLINELEN = 32768;
46cdf0e10cSrcweir
47cdf0e10cSrcweir static TCHAR g_szSTInstallationPath[MAX_PATH] = TEXT("");
48cdf0e10cSrcweir static TCHAR g_szOperatingSystem[256] = TEXT("");
49cdf0e10cSrcweir
50cdf0e10cSrcweir static const TCHAR g_szSTExecutable[256] = TEXT("stclient.exe");
51cdf0e10cSrcweir
52cdf0e10cSrcweir //***************************************************************************
53cdf0e10cSrcweir
RegReadValue(HKEY hBaseKey,LPCTSTR lpSubKey,LPCTSTR lpValueName,LPVOID lpData,DWORD cbData)54cdf0e10cSrcweir LONG RegReadValue( HKEY hBaseKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPVOID lpData, DWORD cbData )
55cdf0e10cSrcweir {
56cdf0e10cSrcweir HKEY hKey = NULL;
57cdf0e10cSrcweir LONG lResult( 0 );
58cdf0e10cSrcweir
59cdf0e10cSrcweir lResult = RegOpenKeyEx( hBaseKey, lpSubKey, 0, KEY_QUERY_VALUE, &hKey );
60cdf0e10cSrcweir
61cdf0e10cSrcweir if ( ERROR_SUCCESS == lResult )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir lResult = RegQueryValueEx( hKey, lpValueName, NULL, NULL, (LPBYTE)lpData, &cbData );
64cdf0e10cSrcweir RegCloseKey( hKey );
65cdf0e10cSrcweir }
66cdf0e10cSrcweir
67cdf0e10cSrcweir return lResult;
68cdf0e10cSrcweir }
69cdf0e10cSrcweir
70cdf0e10cSrcweir //***************************************************************************
71cdf0e10cSrcweir
GetCommandArgs(int * pArgc)72cdf0e10cSrcweir static LPTSTR *GetCommandArgs( int *pArgc )
73cdf0e10cSrcweir {
74cdf0e10cSrcweir #ifdef UNICODE
75cdf0e10cSrcweir return CommandLineToArgvW( GetCommandLineW(), pArgc );
76cdf0e10cSrcweir #else
77cdf0e10cSrcweir *pArgc = __argc;
78cdf0e10cSrcweir return __argv;
79cdf0e10cSrcweir #endif
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
82cdf0e10cSrcweir //***************************************************************************
83cdf0e10cSrcweir
IsSupportedPlatform()84cdf0e10cSrcweir static bool IsSupportedPlatform()
85cdf0e10cSrcweir {
86cdf0e10cSrcweir OSVERSIONINFO aOsVersion;
87cdf0e10cSrcweir
88cdf0e10cSrcweir ZeroMemory( &aOsVersion, sizeof( OSVERSIONINFO ));
89cdf0e10cSrcweir aOsVersion.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
90cdf0e10cSrcweir
91cdf0e10cSrcweir // Try to determine OS version
92cdf0e10cSrcweir if ( GetVersionEx( &aOsVersion ))
93cdf0e10cSrcweir {
94cdf0e10cSrcweir switch ( aOsVersion.dwPlatformId )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir case VER_PLATFORM_WIN32_NT: // Windows NT based
97cdf0e10cSrcweir return true;
98cdf0e10cSrcweir
99cdf0e10cSrcweir case VER_PLATFORM_WIN32_WINDOWS: // Windows Me/98/95.
100cdf0e10cSrcweir case VER_PLATFORM_WIN32s: // Win32s
101cdf0e10cSrcweir return false;
102cdf0e10cSrcweir
103cdf0e10cSrcweir default:
104cdf0e10cSrcweir return false;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir }
107cdf0e10cSrcweir
108cdf0e10cSrcweir return false;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir
111cdf0e10cSrcweir //***************************************************************************
112cdf0e10cSrcweir
GetOperatingSystemString()113cdf0e10cSrcweir static LPCTSTR GetOperatingSystemString()
114cdf0e10cSrcweir {
115cdf0e10cSrcweir OSVERSIONINFO aOsVersion;
116cdf0e10cSrcweir
117cdf0e10cSrcweir ZeroMemory( &aOsVersion, sizeof( OSVERSIONINFO ));
118cdf0e10cSrcweir aOsVersion.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
119cdf0e10cSrcweir
120cdf0e10cSrcweir _tcscpy( g_szOperatingSystem, TEXT( "Microsoft Windows" ));
121cdf0e10cSrcweir
122cdf0e10cSrcweir // Try to determine OS version
123cdf0e10cSrcweir if ( GetVersionEx( &aOsVersion ))
124cdf0e10cSrcweir {
125cdf0e10cSrcweir switch ( aOsVersion.dwPlatformId )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir // Test for the Windows NT product family.
128cdf0e10cSrcweir case VER_PLATFORM_WIN32_NT:
129cdf0e10cSrcweir {
130cdf0e10cSrcweir if ( aOsVersion.dwMajorVersion == 3 )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir _tcscat( g_szOperatingSystem, TEXT( " NT 3." ));
133cdf0e10cSrcweir if ( aOsVersion.dwMinorVersion == 0 )
134cdf0e10cSrcweir _tcscat( g_szOperatingSystem, TEXT( "0" ));
135cdf0e10cSrcweir else if ( aOsVersion.dwMinorVersion == 5 )
136cdf0e10cSrcweir _tcscat( g_szOperatingSystem, TEXT( "5" ));
137cdf0e10cSrcweir else if ( aOsVersion.dwMinorVersion == 51 )
138cdf0e10cSrcweir _tcscat( g_szOperatingSystem, TEXT( "51" ));
139cdf0e10cSrcweir }
140cdf0e10cSrcweir else if ( aOsVersion.dwMajorVersion == 4 )
141cdf0e10cSrcweir _tcscat( g_szOperatingSystem, TEXT( " NT 4.0" ));
142cdf0e10cSrcweir else if ( aOsVersion.dwMajorVersion == 5 )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir if ( aOsVersion.dwMinorVersion == 0 )
145cdf0e10cSrcweir _tcscat( g_szOperatingSystem, TEXT( " 2000" ));
146cdf0e10cSrcweir else if ( aOsVersion.dwMinorVersion == 1 )
147cdf0e10cSrcweir _tcscat( g_szOperatingSystem, TEXT( " XP" ));
148cdf0e10cSrcweir else if ( aOsVersion.dwMinorVersion == 2 )
149cdf0e10cSrcweir _tcscat( g_szOperatingSystem, TEXT( " Server 2003" ));
150cdf0e10cSrcweir }
151cdf0e10cSrcweir else if ( aOsVersion.dwMajorVersion == 6 )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir if ( aOsVersion.dwMinorVersion == 0 )
154cdf0e10cSrcweir _tcscat( g_szOperatingSystem, " Vista" );
155cdf0e10cSrcweir }
156cdf0e10cSrcweir }
157cdf0e10cSrcweir break;
158cdf0e10cSrcweir
159cdf0e10cSrcweir // Test for the Windows Me/98/95.
160cdf0e10cSrcweir case VER_PLATFORM_WIN32_WINDOWS:
161cdf0e10cSrcweir {
162cdf0e10cSrcweir if ( aOsVersion.dwMinorVersion == 0 )
163cdf0e10cSrcweir _tcscat( g_szOperatingSystem, TEXT( " 95" ));
164cdf0e10cSrcweir else if ( aOsVersion.dwMinorVersion == 10 )
165cdf0e10cSrcweir _tcscat( g_szOperatingSystem, TEXT( " 98" ));
166cdf0e10cSrcweir else if ( aOsVersion.dwMinorVersion == 90 )
167cdf0e10cSrcweir _tcscat( g_szOperatingSystem, TEXT( " Me" ));
168cdf0e10cSrcweir }
169cdf0e10cSrcweir break;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir }
172cdf0e10cSrcweir
173cdf0e10cSrcweir return g_szOperatingSystem;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
176cdf0e10cSrcweir //***************************************************************************
177cdf0e10cSrcweir
FileExists(LPCTSTR lpPathToFile)178cdf0e10cSrcweir static bool FileExists( LPCTSTR lpPathToFile )
179cdf0e10cSrcweir {
180cdf0e10cSrcweir bool bResult = false;
181cdf0e10cSrcweir HANDLE hFind;
182cdf0e10cSrcweir WIN32_FIND_DATA FindFileData;
183cdf0e10cSrcweir
184cdf0e10cSrcweir hFind = FindFirstFile( lpPathToFile, &FindFileData );
185cdf0e10cSrcweir
186cdf0e10cSrcweir if ( hFind != INVALID_HANDLE_VALUE )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir FindClose( hFind );
189cdf0e10cSrcweir bResult = true;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir return bResult;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir
195cdf0e10cSrcweir //***************************************************************************
196cdf0e10cSrcweir
GetProgramFilesFolder(LPTSTR strPath)197cdf0e10cSrcweir static bool GetProgramFilesFolder( LPTSTR strPath )
198cdf0e10cSrcweir {
199cdf0e10cSrcweir bool bRet = false;
200cdf0e10cSrcweir HINSTANCE hLibrary;
201cdf0e10cSrcweir
202cdf0e10cSrcweir if (( hLibrary = LoadLibrary( "shell32.dll" )) != NULL )
203cdf0e10cSrcweir {
204cdf0e10cSrcweir BOOL (WINAPI *pSHGetSpecialFolderPathA)( HWND, LPSTR, int, BOOL );
205cdf0e10cSrcweir
206cdf0e10cSrcweir pSHGetSpecialFolderPathA = (BOOL (WINAPI *)(HWND, LPSTR, int, BOOL))GetProcAddress( hLibrary, "SHGetSpecialFolderPathA" );
207cdf0e10cSrcweir
208cdf0e10cSrcweir if ( pSHGetSpecialFolderPathA )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir if ( pSHGetSpecialFolderPathA( NULL, strPath, CSIDL_PROGRAM_FILES, TRUE ))
211cdf0e10cSrcweir bRet = true;
212cdf0e10cSrcweir }
213cdf0e10cSrcweir }
214cdf0e10cSrcweir
215cdf0e10cSrcweir FreeLibrary( hLibrary );
216cdf0e10cSrcweir
217cdf0e10cSrcweir return ( bRet );
218cdf0e10cSrcweir }
219cdf0e10cSrcweir
220cdf0e10cSrcweir //***************************************************************************
221cdf0e10cSrcweir
RetrieveExecutablePath(LPTSTR szExecutablePath)222cdf0e10cSrcweir static PathResult RetrieveExecutablePath( LPTSTR szExecutablePath )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir PathResult eRet = PATHRESULT_API_NOT_SUPPORTED;
225cdf0e10cSrcweir TCHAR szProgramFilesFolder[MAX_PATH];
226cdf0e10cSrcweir
227cdf0e10cSrcweir if ( GetProgramFilesFolder( szProgramFilesFolder ))
228cdf0e10cSrcweir {
229cdf0e10cSrcweir size_t nLen = _tcslen( szProgramFilesFolder );
230cdf0e10cSrcweir if ( nLen > 0 )
231cdf0e10cSrcweir {
232cdf0e10cSrcweir _tcscpy( szExecutablePath, szProgramFilesFolder );
233cdf0e10cSrcweir if ( szProgramFilesFolder[nLen-1] != '\\' )
234cdf0e10cSrcweir _tcscat( szExecutablePath, TEXT( "\\" ));
235cdf0e10cSrcweir _tcscat( szExecutablePath, TEXT( "Sun\\servicetag\\" ));
236cdf0e10cSrcweir _tcscat( szExecutablePath, g_szSTExecutable );
237cdf0e10cSrcweir eRet = FileExists( szExecutablePath ) ? PATHRESULT_OK : PATHRESULT_EXE_NOT_FOUND;
238cdf0e10cSrcweir }
239cdf0e10cSrcweir }
240cdf0e10cSrcweir
241cdf0e10cSrcweir return eRet;
242cdf0e10cSrcweir }
243cdf0e10cSrcweir
244cdf0e10cSrcweir //***************************************************************************
245cdf0e10cSrcweir
SafeCopy(LPTSTR lpTarget,LPCSTR lpSource,size_t nMaxLen)246cdf0e10cSrcweir static void SafeCopy( LPTSTR lpTarget, LPCSTR lpSource, size_t nMaxLen )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir size_t nLen = _tcslen( lpSource );
249cdf0e10cSrcweir size_t nCopy = ( nLen < size_t( nMaxLen-1 )) ? nLen : nMaxLen-1;
250cdf0e10cSrcweir _tcsncpy( lpTarget, lpSource, nMaxLen-1 );
251cdf0e10cSrcweir *(lpTarget+nCopy) = 0;
252cdf0e10cSrcweir }
253cdf0e10cSrcweir
254cdf0e10cSrcweir //***************************************************************************
255cdf0e10cSrcweir
_tWinMain(HINSTANCE,HINSTANCE,LPTSTR,int)256cdf0e10cSrcweir int WINAPI _tWinMain( HINSTANCE /*hInstance*/, HINSTANCE, LPTSTR, int )
257cdf0e10cSrcweir {
258cdf0e10cSrcweir const DWORD ERR_NO_RECORDS_FOUND = 225;
259cdf0e10cSrcweir const DWORD ERR_DUP_RECORD = 226;
260cdf0e10cSrcweir
261cdf0e10cSrcweir DWORD dwExitCode = (DWORD)1;
262cdf0e10cSrcweir
263cdf0e10cSrcweir int nArgs = 0;
264cdf0e10cSrcweir LPTSTR* lpArgs = GetCommandArgs( &nArgs );
265cdf0e10cSrcweir
266cdf0e10cSrcweir if ( !IsSupportedPlatform() )
267cdf0e10cSrcweir {
268cdf0e10cSrcweir // Return 0 for a successful run on not supported platforms
269cdf0e10cSrcweir // We don't want that the Office tries to start us forever.
270cdf0e10cSrcweir return 0;
271cdf0e10cSrcweir }
272cdf0e10cSrcweir
273cdf0e10cSrcweir if ( nArgs >= 11 )
274cdf0e10cSrcweir {
275cdf0e10cSrcweir TCHAR szTargetURN[1024] = {0};
276cdf0e10cSrcweir TCHAR szProductName[1024] = {0};
277cdf0e10cSrcweir TCHAR szProductVersion[1024] = {0};
278cdf0e10cSrcweir TCHAR szParentProductName[1024] = {0};
279cdf0e10cSrcweir TCHAR szProductSource[1024] = {0};
280cdf0e10cSrcweir TCHAR szInstanceURN[1024] = {0};
281cdf0e10cSrcweir
282cdf0e10cSrcweir // -i) INSTANCE_URN="$2"; shift;;
283cdf0e10cSrcweir // -t) TARGET_URN="$2"; shift;;
284cdf0e10cSrcweir // -p) PRODUCT_NAME="$2"; shift;;
285cdf0e10cSrcweir // -e) PRODUCT_VERSION="$2"; shift;;
286cdf0e10cSrcweir // -P) PARENT_PRODUCT_NAME="$2"; shift;;
287cdf0e10cSrcweir // -S) PRODUCT_SOURCE="$2"; shift;;
288cdf0e10cSrcweir // "usage: $0 [-i <instance urn>] -p <product name> -e <product version> -t <urn> -S <source> -P <parent product name>"
289cdf0e10cSrcweir
290cdf0e10cSrcweir int i = 1;
291cdf0e10cSrcweir while ( i < nArgs )
292cdf0e10cSrcweir {
293cdf0e10cSrcweir LPTSTR lpArg = lpArgs[i];
294cdf0e10cSrcweir if ( _tcslen( lpArg ) >= 2 )
295cdf0e10cSrcweir {
296cdf0e10cSrcweir if ( lpArg[0] == '-' )
297cdf0e10cSrcweir {
298cdf0e10cSrcweir switch ( lpArg[1] )
299cdf0e10cSrcweir {
300cdf0e10cSrcweir case 'i':
301cdf0e10cSrcweir {
302cdf0e10cSrcweir if ( i < nArgs )
303cdf0e10cSrcweir ++i;
304cdf0e10cSrcweir SafeCopy( szInstanceURN, lpArgs[i], elementsof( szInstanceURN ));
305cdf0e10cSrcweir break;
306cdf0e10cSrcweir }
307cdf0e10cSrcweir
308cdf0e10cSrcweir case 't':
309cdf0e10cSrcweir {
310cdf0e10cSrcweir if ( i < nArgs )
311cdf0e10cSrcweir ++i;
312cdf0e10cSrcweir SafeCopy( szTargetURN, lpArgs[i], elementsof( szTargetURN ));
313cdf0e10cSrcweir break;
314cdf0e10cSrcweir }
315cdf0e10cSrcweir case 'p':
316cdf0e10cSrcweir {
317cdf0e10cSrcweir if ( i < nArgs )
318cdf0e10cSrcweir ++i;
319cdf0e10cSrcweir SafeCopy( szProductName, lpArgs[i], elementsof( szProductName ));
320cdf0e10cSrcweir break;
321cdf0e10cSrcweir }
322cdf0e10cSrcweir case 'e':
323cdf0e10cSrcweir {
324cdf0e10cSrcweir if ( i < nArgs )
325cdf0e10cSrcweir ++i;
326cdf0e10cSrcweir SafeCopy( szProductVersion, lpArgs[i], elementsof( szProductVersion ));
327cdf0e10cSrcweir break;
328cdf0e10cSrcweir }
329cdf0e10cSrcweir case 'P':
330cdf0e10cSrcweir {
331cdf0e10cSrcweir if ( i < nArgs )
332cdf0e10cSrcweir ++i;
333cdf0e10cSrcweir SafeCopy( szParentProductName, lpArgs[i], elementsof( szParentProductName ));
334cdf0e10cSrcweir break;
335cdf0e10cSrcweir }
336cdf0e10cSrcweir case 'S':
337cdf0e10cSrcweir {
338cdf0e10cSrcweir if ( i < nArgs )
339cdf0e10cSrcweir ++i;
340cdf0e10cSrcweir SafeCopy( szProductSource, lpArgs[i], elementsof( szProductSource ));
341cdf0e10cSrcweir break;
342cdf0e10cSrcweir }
343cdf0e10cSrcweir
344cdf0e10cSrcweir default:
345cdf0e10cSrcweir break;
346cdf0e10cSrcweir } // switch
347cdf0e10cSrcweir }
348cdf0e10cSrcweir }
349cdf0e10cSrcweir
350cdf0e10cSrcweir ++i;
351cdf0e10cSrcweir }
352cdf0e10cSrcweir
353cdf0e10cSrcweir if ( RetrieveExecutablePath( g_szSTInstallationPath ) == PATHRESULT_OK )
354cdf0e10cSrcweir {
355cdf0e10cSrcweir BOOL bSuccess = TRUE;
356cdf0e10cSrcweir BOOL bProcessStarted = FALSE;
357cdf0e10cSrcweir
358cdf0e10cSrcweir STARTUPINFO aStartupInfo;
359cdf0e10cSrcweir PROCESS_INFORMATION aProcessInfo;
360cdf0e10cSrcweir LPTSTR lpCommandLine = 0;
361cdf0e10cSrcweir
362cdf0e10cSrcweir ZeroMemory( &aStartupInfo, sizeof( aStartupInfo ));
363cdf0e10cSrcweir aStartupInfo.cb = sizeof( aStartupInfo );
364cdf0e10cSrcweir ZeroMemory( &aProcessInfo, sizeof( aProcessInfo ));
365cdf0e10cSrcweir
366cdf0e10cSrcweir if ( _tcslen( szInstanceURN ) == 0 )
367cdf0e10cSrcweir {
368cdf0e10cSrcweir // TEST=`${STCLIENT} -f -t ${TARGET_URN}`
369cdf0e10cSrcweir lpCommandLine = new TCHAR[MAXCMDLINELEN];
370cdf0e10cSrcweir
371cdf0e10cSrcweir _tcscpy( lpCommandLine, TEXT( "\"" ));
372cdf0e10cSrcweir _tcscat( lpCommandLine, g_szSTInstallationPath );
373cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
374cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( " -f" ));
375cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( " -t "));
376cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
377cdf0e10cSrcweir _tcscat( lpCommandLine, szTargetURN );
378cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
379cdf0e10cSrcweir
380cdf0e10cSrcweir bSuccess = CreateProcess(
381cdf0e10cSrcweir NULL,
382cdf0e10cSrcweir lpCommandLine,
383cdf0e10cSrcweir NULL,
384cdf0e10cSrcweir NULL,
385cdf0e10cSrcweir TRUE,
386cdf0e10cSrcweir CREATE_NO_WINDOW,
387cdf0e10cSrcweir NULL,
388cdf0e10cSrcweir NULL,
389cdf0e10cSrcweir &aStartupInfo,
390cdf0e10cSrcweir &aProcessInfo );
391cdf0e10cSrcweir
392cdf0e10cSrcweir bProcessStarted = TRUE;
393cdf0e10cSrcweir
394cdf0e10cSrcweir // wait until process ends to receive exit code
395cdf0e10cSrcweir WaitForSingleObject( aProcessInfo.hProcess, INFINITE );
396cdf0e10cSrcweir
397cdf0e10cSrcweir delete []lpCommandLine;
398cdf0e10cSrcweir }
399cdf0e10cSrcweir
400cdf0e10cSrcweir if ( bSuccess )
401cdf0e10cSrcweir {
402cdf0e10cSrcweir DWORD dwSTClientExitCode( ERR_NO_RECORDS_FOUND );
403cdf0e10cSrcweir if ( bProcessStarted )
404cdf0e10cSrcweir {
405cdf0e10cSrcweir GetExitCodeProcess( aProcessInfo.hProcess, &dwSTClientExitCode );
406cdf0e10cSrcweir dwSTClientExitCode &= 0x000000ff;
407cdf0e10cSrcweir
408cdf0e10cSrcweir CloseHandle( aProcessInfo.hProcess );
409cdf0e10cSrcweir CloseHandle( aProcessInfo.hThread );
410cdf0e10cSrcweir }
411cdf0e10cSrcweir
412cdf0e10cSrcweir if ( dwSTClientExitCode == ERR_NO_RECORDS_FOUND )
413cdf0e10cSrcweir {
414cdf0e10cSrcweir // output=`${STCLIENT} -a [-i "${INSTANCE_URN}"] -p "${PRODUCT_NAME}" -e "${PRODUCT_VERSION}" -t "${TARGET_URN}" -S "${PRODUCT_SOURCE}" -P "${PARENT_PRODUCT_NAME}" -m "Sun Microsystems, Inc." -A ${uname} -z global`
415cdf0e10cSrcweir lpCommandLine = new TCHAR[MAXCMDLINELEN];
416cdf0e10cSrcweir
417cdf0e10cSrcweir _tcscpy( lpCommandLine, TEXT( "\"" ));
418cdf0e10cSrcweir _tcscat( lpCommandLine, g_szSTInstallationPath );
419cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
420cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( " -a" ));
421cdf0e10cSrcweir if ( _tcslen( szInstanceURN ) > 0 )
422cdf0e10cSrcweir {
423cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( " -i " ));
424cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
425cdf0e10cSrcweir _tcscat( lpCommandLine, szInstanceURN );
426cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
427cdf0e10cSrcweir }
428cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( " -p " ));
429cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
430cdf0e10cSrcweir _tcscat( lpCommandLine, szProductName );
431cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
432cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( " -e " ));
433cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
434cdf0e10cSrcweir _tcscat( lpCommandLine, szProductVersion );
435cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
436cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( " -t " ));
437cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
438cdf0e10cSrcweir _tcscat( lpCommandLine, szTargetURN );
439cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
440cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( " -S " ));
441cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
442cdf0e10cSrcweir _tcscat( lpCommandLine, szProductSource );
443cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
444cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( " -P " ));
445cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
446cdf0e10cSrcweir _tcscat( lpCommandLine, szParentProductName );
447cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
448cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( " -m \"Sun Microsystems, Inc.\"" ));
449cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( " -A " ));
450cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
451cdf0e10cSrcweir _tcscat( lpCommandLine, GetOperatingSystemString() );
452cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( "\"" ));
453cdf0e10cSrcweir _tcscat( lpCommandLine, TEXT( " -z global" ));
454cdf0e10cSrcweir
455cdf0e10cSrcweir ZeroMemory( &aStartupInfo, sizeof( aStartupInfo ));
456cdf0e10cSrcweir aStartupInfo.cb = sizeof(aStartupInfo);
457cdf0e10cSrcweir ZeroMemory( &aProcessInfo, sizeof( aProcessInfo ));
458cdf0e10cSrcweir
459cdf0e10cSrcweir bSuccess = CreateProcess(
460cdf0e10cSrcweir NULL,
461cdf0e10cSrcweir lpCommandLine,
462cdf0e10cSrcweir NULL,
463cdf0e10cSrcweir NULL,
464cdf0e10cSrcweir TRUE,
465cdf0e10cSrcweir CREATE_NO_WINDOW,
466cdf0e10cSrcweir NULL,
467cdf0e10cSrcweir NULL,
468cdf0e10cSrcweir &aStartupInfo,
469cdf0e10cSrcweir &aProcessInfo );
470cdf0e10cSrcweir
471cdf0e10cSrcweir delete []lpCommandLine;
472cdf0e10cSrcweir
473cdf0e10cSrcweir // wait until process ends to receive exit code
474cdf0e10cSrcweir WaitForSingleObject( aProcessInfo.hProcess, INFINITE );
475cdf0e10cSrcweir
476cdf0e10cSrcweir dwSTClientExitCode = 0;
477cdf0e10cSrcweir GetExitCodeProcess( aProcessInfo.hProcess, &dwSTClientExitCode );
478cdf0e10cSrcweir dwSTClientExitCode &= 0x000000ff;
479cdf0e10cSrcweir
480cdf0e10cSrcweir CloseHandle( aProcessInfo.hProcess );
481cdf0e10cSrcweir CloseHandle( aProcessInfo.hThread );
482cdf0e10cSrcweir
483cdf0e10cSrcweir if ( !bSuccess )
484cdf0e10cSrcweir dwExitCode = 1; // couldn't start stclient process
485cdf0e10cSrcweir else
486cdf0e10cSrcweir {
487cdf0e10cSrcweir if ( _tcslen( szInstanceURN ) > 0 )
488cdf0e10cSrcweir {
489cdf0e10cSrcweir // don't register again if we registered in a previous run
490cdf0e10cSrcweir // or we called stclient successfully.
491cdf0e10cSrcweir if (( dwSTClientExitCode == ERR_DUP_RECORD ) ||
492cdf0e10cSrcweir ( dwSTClientExitCode == 0 ))
493cdf0e10cSrcweir dwExitCode = 0;
494cdf0e10cSrcweir else
495cdf0e10cSrcweir dwExitCode = 1; // other errors
496cdf0e10cSrcweir }
497cdf0e10cSrcweir else
498cdf0e10cSrcweir dwExitCode = ( dwSTClientExitCode == 0 ) ? 0 : 1;
499cdf0e10cSrcweir }
500cdf0e10cSrcweir }
501cdf0e10cSrcweir else if ( dwSTClientExitCode == 0 )
502cdf0e10cSrcweir dwExitCode = 0; // already registered
503cdf0e10cSrcweir else
504cdf0e10cSrcweir dwExitCode = 1; // other errors
505cdf0e10cSrcweir }
506cdf0e10cSrcweir else
507cdf0e10cSrcweir dwExitCode = 1; // couldn't start stclient
508cdf0e10cSrcweir }
509cdf0e10cSrcweir else
510cdf0e10cSrcweir dwExitCode = 1; // no executable found
511cdf0e10cSrcweir }
512cdf0e10cSrcweir else
513cdf0e10cSrcweir dwExitCode = 0; // wrong number of arguments
514cdf0e10cSrcweir
515cdf0e10cSrcweir return dwExitCode;
516cdf0e10cSrcweir }
517