Share via


How do I launch a browser after my install completes?

Question

How do I launch a browser after my install completes?

Solution

Please have a look at the MSDN topic: Using a Custom Action to Launch an Installed File at the End of the Installation

Key Custom Action Snippit from Tutorial.cpp from Windows Installer Section of Platform SDK

 //////////////////////////////////////////////////////////////////////////////
// LaunchTutorial
//
// Launches a installed file at the end of setup
//
UINT __stdcall LaunchTutorial(MSIHANDLE hInstall)
{
    BOOL fSuccess = FALSE;

  // szTutorialFileKey is the primary key of the file in the
  // File table that identifies the file we wish to launch
    const TCHAR szTutorialFileKey[] = TEXT("[#Tutorial]");

  PMSIHANDLE hRecTutorial = MsiCreateRecord(1);

   if ( !hRecTutorial
      || ERROR_SUCCESS != MsiRecordSetString(hRecTutorial, 0, szTutorialFileKey))
     return ERROR_INSTALL_FAILURE;

   // determine buffer size
    DWORD cchPath = 0;
  if (ERROR_MORE_DATA == MsiFormatRecord(hInstall, hRecTutorial, TEXT(""), &cchPath))
 {
       // add 1 to cchPath since return count from MsiFormatRecord does not include terminating null
       TCHAR* szPath = new TCHAR[++cchPath];
       if (szPath)
     {
           if (ERROR_SUCCESS == MsiFormatRecord(hInstall, hRecTutorial, szPath, &cchPath))
         {
               // ensure quoted path to ShellExecute
               DWORD cchQuotedPath = lstrlen(szPath) + 1 + 2; // szPath + null terminator + enclosing quotes
               TCHAR* szQuotedPath = new TCHAR[cchQuotedPath];
             if (szQuotedPath
                    && SUCCEEDED(StringCchCopy(szQuotedPath, cchQuotedPath, TEXT("\"")))
                    && SUCCEEDED(StringCchCat(szQuotedPath, cchQuotedPath, szPath))
                 && SUCCEEDED(StringCchCat(szQuotedPath, cchQuotedPath, TEXT("\""))))
                {
                   // set up ShellExecute structure
                    // file is the full path to the installed file
                  SHELLEXECUTEINFO sei;
                   ZeroMemory(&sei, sizeof(SHELLEXECUTEINFO));
                 sei.fMask = SEE_MASK_FLAG_NO_UI; // don't show error UI, we'll just silently fail
                   sei.hwnd = 0;
                   sei.lpVerb = NULL; // use default verb, typically open
                  sei.lpFile = szQuotedPath;
                  sei.lpParameters = NULL;
                    sei.lpDirectory = NULL;
                 sei.nShow = SW_SHOWNORMAL;
                  sei.cbSize = sizeof(sei);

                   // spawn the browser to display HTML tutorial
                   fSuccess = ShellExecuteEx(&sei);

                    delete [] szQuotedPath;
             }
           }
           delete [] szPath;
       }
   }

   return (fSuccess) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
}