Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - How to prompt for elevation for a single operation?

Reply
 
Old 07-15-2008   #1 (permalink)
Oolis Kraprin


 
 

How to prompt for elevation for a single operation?

Oolis Kraprin wrote:
Quote:

> Hi, I have a program running with normal user privileges, that needs
> to update an entry in an ini file that happens to be in ProgramData,
> so that a server program, running as administrator can read it.
> Editing the ini file directly causes only the VirtualStore copy to be
> edited, so my plan is to prompt for elevation as administrator before
> this edit and restore normal user permission after. If the elevation
> fails then a message box reminding the user to edit the file as admin
> is sufficient.
>
Best as I can tell, you can't do this. Elevation happens at the start of a
process and you can't change elevation status once the process is running.

You can delegate the task to a helper application that's marked as requiring
administrative privileges. I don't know of a native way to check whether
your own application is being virtualized in .NET, but you can use P/Invoke
to call OpenProcessToken() and GetTokenInformation() with the
TokenVirtualizationEnabled flag. If your application detects that it's
virtualized, it could call the helper application.

All this may be more trouble than it's worth, if a reminder is already
acceptable.

--
J.

My System SpecsSystem Spec
Old 07-15-2008   #2 (permalink)
Jeroen Mostert


 
 

Re: How to prompt for elevation for a single operation?

Oolis Kraprin wrote:
Quote:

> Hi, I have a program running with normal user privileges, that needs
> to update an entry in an ini file that happens to be in ProgramData,
> so that a server program, running as administrator can read it.
> Editing the ini file directly causes only the VirtualStore copy to be
> edited, so my plan is to prompt for elevation as administrator before
> this edit and restore normal user permission after. If the elevation
> fails then a message box reminding the user to edit the file as admin
> is sufficient.
>
Best as I can tell, you can't do this. Elevation happens at the start of a
process and you can't change elevation status once the process is running.

You can delegate the task to a helper application that's marked as requiring
administrative privileges. I don't know of a native way to check whether
your own application is being virtualized in .NET, but you can use P/Invoke
to call OpenProcessToken() and GetTokenInformation() with the
TokenVirtualizationEnabled flag. If your application detects that it's
virtualized, it could call the helper application.

All this may be more trouble than it's worth, if a reminder is already
acceptable.

--
J.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
the requested operation requires elevation System Security
Operation Requires Elevation General Discussion
The requested operation requires elevation Vista security
This Requested Operation Needs Elevation Vista account administration
Requested operation require elevation Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46