Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will Windows 7 pop up a message when an application needs administrator privileges?

What will happen when I write an application that needs to do something "adminable"?

Like writing files to C:\Program Files - then, when the application tries to do this, what will happen? Will a message be popped up asking the user for a password? Will an exception be thrown? Will the program terminate and will the computer explode? All of the above? :)

On a side note: Are Windows 7 users logged by default as administrators?

like image 970
johny Avatar asked Apr 04 '11 17:04

johny


1 Answers

In general, Windows Vista and Windows 7 will not automatically detect that you need admin rights, and will not elevate your application automatically. Microsoft has some guidelines for properly requesting elevation. Older applications without a manifest may find themselves virtualized as well - that is, your write to program files may be redirected to a directory under the user's profile directory.

Keep in mind that you should keep privileged operations to an absolute minimum. UAC exists to discourage application developers from requesting unnecessary administrative access, in order to improve security. The only programs that should be messing with program files are installers.

Note that Administrative users on Windows 7/Vista cannot use their rights without elevating - the Administrator token has a higher integrity level than processes run at by default, and as such cannot be accessed. If you attempt to perform an operation which requires such access, you will receive an access denied error; the underlying APIs won't throw any kind of exception, they'll just typically fail and set GetLastError() to ERROR_ACCESS_DENIED. Higher level APIs, of course, may choose to convert this to a thrown exception, or to terminate violently, although the latter is quite rude, and unlikely to occur in any built-in windows APIs.

like image 70
bdonlan Avatar answered Oct 02 '22 14:10

bdonlan