0

Is there a way to detect what prevents an app from running in a non-elevated state? When we run our application with elevated permissions it operates without any problems. Running in a non-elevated state prevents the application from starting.

Are there any tricks to detecting what might be preventing the app from running non-elevated?

Our application does not write data to a protected folder, i.e. program files.

Patrick
  • 17,669
  • 6
  • 70
  • 85
Rupert Puxton
  • 53
  • 1
  • 5
  • Which type of project? WinForms, WPF, Console? Try Debug->Exceptions in VS and check Thrown next to Common Language Runtime Exceptions. This will prevent any try/catch blocks from swallowing exceptions. – TheEvilPenguin Nov 14 '12 at 23:41
  • WinForms (.NET 4). We are compiling the application and installing the binaries onto a separate computer, non-elevated. We need to detect what prevents the app from running as a compiled binary. – Rupert Puxton Nov 14 '12 at 23:57

2 Answers2

3

You can view the exceptions it threw in Windows Event Viewer (not the most efficient method) or wrap the whole program with an exception handler that displays or logs the exception info (a better approach if you have the luxury of being able to edit and build the project). Once you have the exception it shouldn't be too much trouble finding the operations where you have insufficient privileges.

evanmcdonnal
  • 46,131
  • 16
  • 104
  • 115
  • Managed to find the exception details in the Windows Event Viewer. For those interested the issue is an UnauthorizedAccessException when using Shell32 to inspect a shortcut. Your solution now has us on the right track. – Rupert Puxton Nov 15 '12 at 00:14
1

You should log errors to a file (or to the console, or whatever you like) to see which instruction is causing the problem. You could also detect the error in debug, but for this VS must not be running as admin.

Anyway, the most common cause is that you're trying to write to a directory which is writable only with elevated privileges (e.g. Program Files, Windows...), or a registry key in any hive other than HKEY_CURRENT_USER.

Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758