the default and recommended way is to let Windows replace the file at the next reboot.

If you would like to stop the installation, you can use the "Check In-user File..." and/or "Check In-use Folder Tree..." script functions and then act accordantly (e.g. ask the user to stop the app or kill a service and wait, then check again if it is still locked), or Exit the install.

You should do it BEFORE you begin to modify the system.