How to use ExitExecRestart to Install System Files (114606)



The information in this article applies to:

  • Microsoft Windows Software Development Kit (SDK) 3.1
  • Microsoft Win32 Software Development Kit (SDK) 3.5

This article was previously published under Q114606

SUMMARY

Some installation procedures require the installation of files (such as CTL3D.DLL, COMMDLG.DLL, and fonts) that may be in use by Windows at the time the setup program is run. Windows is likely to have these files open, so they cannot be installed without causing sharing violations. The Setup Toolkit provides features to exit Windows, install these files, and then restart Windows when complete.

MORE INFORMATION

The Setup Toolkit accomplishes the installation of system files as follows:

  1. Before the Setup Toolkit copies a system file, it checks to see if the file is currently open. If it is, it copies the file to the destination directory, but under a different file name. It then adds this file to the "restart list".
  2. When CopyFilesInCopyList() is complete, the Setup Toolkit checks the "restart list" and generates a .BAT file (named _MSSETUP.BAT) in the "restart directory". This .BAT file contains commands which delete the system files which were open (in step #1) and rename the new versions to their correct names.
  3. Windows is exited, the .BAT file executed, then Windows restarted.
  4. The .BAT file is then deleted.

    NOTE: The "restart directory" is not deleted. Hence, you should use your application's installation directory as your restart directory.
Hence, to install system files, perform the following steps:

  1. Mark the system files as "system" in the DSKLAYT program. This is accomplished by highlighting all the system files (clicking with the CTRL key down) and placing a check in the "System File" check box under "File Attributes".
  2. Before calling CopyFilesInCopyList() specify the name of your "restart directory". Assuming the target directory for your application is stored in DEST$ (as in the samples), use the following line:
          SetRestartDir DEST$
    						
    The specified directory does not need to exist. It will be created if necessary.
  3. After your installation is complete, execute the following code before exiting your setup script. Normally this code will be placed at the end of the Install subroutine.
          if RestartListEmpty ()=0 then
              '' The following two lines must go on one line.
              MessageBox hwndFrame (), "Windows will now be exited and
              restarted.", "Sample Setup Script", MB_OK+MB_ICONINFORMATION
          eer:
              i%=ExitExecRestart ()
              '' The following three lines must go on one line.
              MessageBox hwndFrame (), "Windows cannot be restared because
              MS-DOS-based applications are active. Close all MS-DOS-based
              applications, and then click OK.", "Sample Setup Script",
              MB_OK+MB_ICONSTOP
              goto eer
          end if
    						
    NOTE: In order to use the MessageBox() function you must add the following lines at the beginning of your setup script:
          const MB_ICONINFORMATION = 64
          '' The following two lines must go on one line.
    
          declare sub MessageBox lib "user.exe" (hwnd%, message$,
          title$, options%)
    						
  4. Add the file _MSSETUP.EXE to your source directory and lay it out on Disk #1 in DSKLAYT.
  5. Add a reference to _MSSETUP.EXE to the [files] section of your .LST file. For example,

    if you marked _MSSETUP.EXE to be compressed,
        [files]
            _mssetup.ex_ = _mssetup.exe
    						
    if you did not mark it as compressed,
        [files]
            _mssetup.exe = _mssetup.exe
NOTES:

  1. If ExitExecRestart () is successful, your script will be exited. That is, ExitExecRestart () will not return. If it does return, an error has occurred.
  2. This functionality is not available under Windows 3.0. If the user runs the above setup script on Windows 3.0, they will receive the message that MS-DOS-based applications are running and they will not be able to complete the setup. If this is a concern, check the version of Windows before executing the above code.
  3. If _MSSETUP.EXE is not in your .LST file or not laid out in DSKLAYT, you will receive an "assertion failure" message when calling ExitExecRestart ().

Modification Type:MajorLast Reviewed:10/29/2003
Keywords:KB114606 kbAudDeveloper