Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elevating Permissions Under Windows 7

I have an 'auto-upgrade' mechanism that has been working for many years under Windows XP which fails under Windows 7 because the prompt to the User (which never existed under under Windows XP) to grant the program permission to run with administrator rights does not appear.

The win32 program (written in Borland Delphi) uses LogonUser() and ImpersonateLoggedOnUser() to impersonate a user (local account with administrator rights) so that it can replace selected files in the Program Files folder.

If I manually logon to Windows 7 using this user account and then attempt to delete a file in the Program Files folder Windows 7 prompts for my permission to allow the program to proceed - if I give it permission the file is deleted, if I deny permission 'access denied' is reported and the deletion is not allowed.

When attempting the same thing as described above 'access denied' is the result without any prompt to the user being given.

I see in a similar question herabouts (regarding the creation of temporary files (where the main thrust of the answers given is quite rightly 'don't do it') that such a prompt can be raised 'in code' but I cannot see where that method is actually explained.

like image 250
S L Bentall Avatar asked May 25 '11 22:05

S L Bentall


1 Answers

You just need to mark your auto updater as requiring elevated privileges in your application manifest.

That said you might want to consider installing somewhere the user has write privileges.

like image 82
David Heffernan Avatar answered Oct 13 '22 19:10

David Heffernan