Prompting+for+admin+rights

//by Richard Russell, December 2012//

If your program needs to perform an action that requires Administrator Privileges (for example it needs to write files to one of the 'protected' areas like **Program Files**) it will fail if run by a standard user. A low-tech approach to this problem is to inform your users that they need to execute the program using the **Run As** option (e.g. by right-clicking on your program's icon and selecting 'Run As...' from the context menu) but a better solution is available.

You can arrange that when your program runs it will prompt the user to grant elevated privileges. This is the technique normally used by installers, because commonly a setup program will need to copy files to areas which are normally protected. The steps required to achieve this are as follows:


 * 1.** Copy this file into the directory containing your program's source (.BBC) code:



code format="bb4w" REM!Resource @dir$+"manifest_admin.res" REM!Window code The purpose of the **REM!Window** directive is to disable the 'Use Windows XP Visual Styles' option. If you need to set the default window size or state add the necessary parameters to the directive, but omit the **xpstyle** option (the replacement manifest has the same effect).
 * 2.** Add these compiler directives to your program:


 * 3.** Re-compile your program.

You should find that if you run the compiled program under Windows Vista, 7 or 8 a standard user will be prompted to allow the program to modify the system. This assumes the user's consent policy has been set to 'Prompt for Credentials', which is normal on a home PC (on a corporate PC standard users may not be given administrator rights).