Detecting if an application is running as an elevated process, and spawning a new process using elevated permissions
Recently I was writing some code to allow a program to register itself to start with Windows for all users. On Windows 7 with User Account Control (UAC) enabled, trying to write to the relevant registry key without having elevated permissions throws an
UnauthorizedAccessException exception. If you want to make these sorts of modifications to a system, the application needs to be running as an administrator.
To check if your application is currently running with elevated permissions, you simply need to see if the current user belongs to the
Administrator user group.