Friday, 4 September 2009

Using your browser to run an .msi as admin

Programmers should not use administrator accounts when developing. They should use accounts with the same privileges as the end users of the software. This minimises the chance of permission-related "it works on my machine" bugs occurring.

Trouble is, developers frequently need to install programs. The nice way to handle this is to use something like sudo (for *nix systems). A specific command can be executed with raised permissions, but for the rest of the time the user operates with normal privileges.

However, some operating systems (like Windows XP), do not fully support the sudo approach. There is a command known as "runas", but this does not work in all circumstances. In particular, it is not available for .msi installer files.

If you are running Windows XP on a non-administrator account, you need to install an .msi and you have the password of an administrator account, you do not have to take the trouble to logout and log back in. The following workaround lets you use your web browser as an .msi launcher and bypass the restriction:
  1. Use runas to launch your browser with admin privileges
  2. Open the .msi in your browser, either from the web or your local filesystem
  3. What you do next depends on what browser you use. In Firefox, you double click on the .msi in the download window which will launch it - as admin!
This works because a child process inherits its permissions from its parent.

Needless to say, use this trick sparingly. Running your browser as administrator all the time is almost as bad as developing under an admin account.