A message appears when your application requests it for some reason. You can manage it using the application manifest. For more information on how to add a manifest, see Create and insert an application manifest file (UAC) .
I suggest you the following:
- Separate your Updater and Update Checker so that they are in different .EXE files.
- UpdateChecker.exe does not require administrator rights, therefore the
requestedExecutionLevel element of the manifest has the level of asInvoker . - Updater.exe requires administrator rights because it writes the updated application file to Program Files. Therefore, the
requestedExecutionLevel element of its manifest has a requireAdministrator level.
In your program, you can run UpdateChecker.exe as you like. To run Updater.exe, you will need to use ShellExecute ; if the application has a manifest (and I highly recommend a manifest attachment), it will show a UAC prompt for promotion if the application wants to get administrator privileges. There is no need to use the verb runas .
Alternatively, you can check if an update is available or not from the main application. And run Updater.exe only if there is a new version on the server.
Another option would be to make Updater.exe check for updates and apply it, if any, as it is now. In this case, Updater.exe should have asInvoker level in its manifest. When it starts without parameters, it checks for a new version on the server. If it finds a newer version, it starts again with administrator privileges and passes a command-line option, such as /doUpdate , which indicates that it is performing the actual update.
In order to restart itself, it must use the ShellExecute and runas verb functions, because ShellExecute will not be able to automatically detect your Updater.exe now requires administrative privileges.
Keep in mind that the meaning of the runas verb is different from Windows XP and Windows Vista / 7, so you must deal with this situation if you want to support previous versions of Windows. The first approach I described will work in Windows XP without additional processing.
Alexey Ivanov
source share