5

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
johny
  • 115
  • 1
  • 4

1 Answers1

7

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.

bdonlan
  • 224,562
  • 31
  • 268
  • 324
  • the links seems really helpfull, thanks - i am going (hopefully) to test the app and see at which uac profile it applies. And are 7/vista users logged by default as admins whereas a password is never required? In linux for instance i can log in in mandriva as root and do everything - while in debian i can't do this even if i want to - or so i think. In xp i am almost always logged as admin and can do everything. – johny Apr 04 '11 at 17:31
  • 1
    No. Admin in 7/vista is similar to an administrative user with sudo rights on Debian or Ubuntu, and UAC is similar to the sudo operation. And stop logging in as root on mandriva! :) – bdonlan Apr 04 '11 at 17:32