User Tools

Site Tools


prompting_20for_20admin_20rights

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:

manifest_admin.res

2. Add these compiler directives to your program:

        REM!Resource @dir$+"manifest_admin.res"
        REM!Window

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).

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).

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
prompting_20for_20admin_20rights.txt · Last modified: 2024/01/05 00:21 by 127.0.0.1