views:

23

answers:

1

I have an application that uses an COM file. Sometimes this file has not been registered by regsvr32 and i'd like to program a function that if the file cannot be loaded it tries to register it and retry. To do so i'd need admin privileges, so i'd like to ask if there's a way to show the UAC "run as administrator" question to the user at those times to have the rights to register the file and than switch it off (if possible, if not it'd be run "normal" at the next application execution). Now i'm just planning to launch another program with a manifest set to run it as admin but i've seen some installations that run without asking admin permission and when the progress bar is starting they show the UAC question to the user, so i'd like to do something like that. Is there a Win32 API function or library to do that?

Thanks

A: 

Your approach is correct. It is not possible to elevate a process. You are launched elevated or you are not, and you stay that way for the lifetime of the process. To achieve what you want, you must launch a different process, and launch it as elevated. Your mainline app stays non-elevated. The UAC prompt will appear when the second process launches. For the sake of a good user experience you should have a button or menu item to do the launching, and that item should have a shield on it. That way the user is not surprised. If you detect programmatically that you need to launch, at least do a message box first saying "I've detected that you need to install XYZ, are you ok with that?" and put a shield on OK, no shield on Cancel, and if they click OK then launch the manifested application. This will trigger a UAC prompt and the user will be expecting it.

Kate Gregory

related questions