1

Possible Duplicate:
How to force C# App to run as administrator on Windows 7

I have created a .NET application which does some file handling stuff. The problem I'm facing in Windows Vista and Windows 7 is that if the user doesn't right-click to run the application as an administrator he/she gets an unhanded exception window.

Is there a way to bypass this? Below, you'll find the image of what I get

Following is the stacktrace:-

************** Exception Text **************
System.UnauthorizedAccessException: Please run the application as an administrator
   at .(Object , EventArgs )
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Please let me know if there's something that could be done to avoid it.

Thanks, Ron

Community
  • 1
  • 1
Rohan
  • 871
  • 1
  • 16
  • 32
  • Look at a non-obfuscated stack trace and find the resulting code. – SLaks Jan 06 '12 at 19:06
  • Similar? http://stackoverflow.com/questions/17533/request-windows-vista-uac-elevation-if-path-is-protected#17544 – sblom Jan 06 '12 at 19:08
  • The reason you're getting the exception is that the OnLoad handler for your application is attempting to access something which requires administrative access. Unfortunately, without knowing what the code is at the location which is throwing the exception, it's not possible to diagnose the problem further. – Larry Osterman Jan 07 '12 at 15:35

0 Answers0