UAC compatible application advice needed

N

Nick Rivers

Hi!

I need to write an UAC compatible application that should work for standard
and admin users.

This application should use DIFx 2.1 to install or update a hardware device,
but only if necessary.

What I´ve done so far:
-linked DIFxAPI.lib
-embedded .manifest with 'highestAvailable' privileg setting
-check the users token to determine if the user has privileges to install or
update a device driver if necessary
-using DriverPackageInstall to install/update device driver

When a standard user runs my application and the hardware device needs to be
installed or updated he will be prompted that he needs admin rights to
install/update the hardware device. UAC does not prompt.

When a admin group user runs my application UAC prompts with the "A program
needs your permission to continue" dialog and then runs through installing
or updating the device if necessary.

I am not sure if this is the correct and best way to create the application.
Best for me would be, if UAC would not prompt any dialogs for all users. I
know that I could also use ShellExecuteEx with 'RunAs' to launch an
executable that needs admin privileges.

I really appreciate any advice or improvement.

Thanks
-Nick
 
D

David Hearn

Nick said:
Hi!

I need to write an UAC compatible application that should work for standard
and admin users.

This application should use DIFx 2.1 to install or update a hardware device,
but only if necessary.

What I´ve done so far:
-linked DIFxAPI.lib
-embedded .manifest with 'highestAvailable' privileg setting
-check the users token to determine if the user has privileges to install or
update a device driver if necessary
-using DriverPackageInstall to install/update device driver

When a standard user runs my application and the hardware device needs to be
installed or updated he will be prompted that he needs admin rights to
install/update the hardware device. UAC does not prompt.

When a admin group user runs my application UAC prompts with the "A program
needs your permission to continue" dialog and then runs through installing
or updating the device if necessary.

I am not sure if this is the correct and best way to create the application.
Best for me would be, if UAC would not prompt any dialogs for all users. I
know that I could also use ShellExecuteEx with 'RunAs' to launch an
executable that needs admin privileges.

I really appreciate any advice or improvement.

Thanks
-Nick

I've not done any UAC development yet, but I have attended a couple of
MS training events which have covered this.

If your app's manifest is requesting 'highestAvailable' - I believe this
simply means, rather than run as a standard user, acquire the full
rights for this class of user. So, if a standard user runs, then the
full rights for this user is just standard. If an Admin user runs it,
then the full rights for this user is Elevated (ie. full Admin).

What I suspect you need is 'requireAdministrator' which for an Admin, is
just to Elevate and get the full permissions of that user (same effect
as highestAvailable would have. But for a standard user, that is to
require an Admin username + password to be entered.

The solution to your problem of not asking all users for UAC permission,
is what MS recommends and to separate out all Elevated code into a
separate assembly (with a .manifest requesting 'requireAdministrator'.
Main code's manifest requests 'asInvoker'. In this case, if no
elevation is required (ie. driver is installed/up to date, no changes
required) then no UAC prompt is seem. If the driver does require
updating, then execute the separate assembly, which itself requests
elevation, and then when it's finished exits and control returns to the
original code, which never left the 'asInvoker' privs.

Does that sound right?

I hope that helps,

David
 
R

Roger Abell [MVP]

Aside for correct ways to program/package for UAC compliance . . .

When you say
Best for me would be, if UAC would not prompt any dialogs for all users.

it shows that you are missing the point of UAC, ie. that use of elevated
privilege, unseen by the user, is not supposed to be under programmatic
control when these features are enabled.
IOW, that you test and avoid when the context cannot have sufficient
privilege is great, but you should not expect to suppress all notices.
 
K

Kerry Brown

Nick Rivers said:
Hi!

I need to write an UAC compatible application that should work for
standard and admin users.

This application should use DIFx 2.1 to install or update a hardware
device, but only if necessary.

What I´ve done so far:
-linked DIFxAPI.lib
-embedded .manifest with 'highestAvailable' privileg setting
-check the users token to determine if the user has privileges to install
or
update a device driver if necessary
-using DriverPackageInstall to install/update device driver

When a standard user runs my application and the hardware device needs to
be installed or updated he will be prompted that he needs admin rights to
install/update the hardware device. UAC does not prompt.

When a admin group user runs my application UAC prompts with the "A
program needs your permission to continue" dialog and then runs through
installing or updating the device if necessary.

I am not sure if this is the correct and best way to create the
application. Best for me would be, if UAC would not prompt any dialogs for
all users. I know that I could also use ShellExecuteEx with 'RunAs' to
launch an executable that needs admin privileges.

I really appreciate any advice or improvement.

Thanks
-Nick


If the program needs to do something that requires administrator privileges
then at some point everyone using that function of the program will see a
uac prompt including administrators. That is the whole point of uac, to
notify the user that the program is doing something that will affect the
system and give them the choice to allow it or not. You can either set the
program to run in administrator mode or program it ask for elevated
privileges only when it actually needs them. In the first case everyone who
runs the program will see a uac prompt every time they run the program. In
the second case only those people using the function that requires
administrator privileges will see the uac prompt.

There are some good tips in some of the documents you can download here:

http://msdn2.microsoft.com/en-us/windowsvista/aa904987.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top