views:

144

answers:

3

I'm doing some WinForms development, running XP and VS 2005 (ancient, I know). I'd like to make sure my application can run without admin rights, but I'm too lazy to try to run VS as a non-admin, and I don't want to log in and out to test my app.

Is there a way I can just debug as a non-admin?

Is there a set of code access security attributes I can add to my code that will force me to run in the same permission set as a non admin?

+2  A: 

Run VS as another user from your current logged in desktop session. See How to enable and use the "Run As" command when running programs in Windows. This means you won't have to log-in and out.

I would suggest that you just run your target application as another user, via RunAs, then attach the VS Debugger to the process (if needed), via the Debug > Attach To Process... menu item in Visual Studio.

Phil Price
A: 

Building on Phil's answer, you can automate the process by setting the startup project to:

Start the external program: c:\windows\system32\runas.exe

with the Command line arguments: /noprofile /user:{MachineName}\{UserName} {ApplicationName}.exe

Unfortunately, I don't think there is an automatic way to attach the process to the VS debugger (because of the security warning), but by conditionally calling

#if (DEBUG) 
    System.Diagnostics.Debugger.Launch();
#endif

you will be prompted to attach to a debugger with two clicks.

foson
A: 

Approaching this with a more fundamental change:

If you enable your computer to allow concurrent Remote Desktop sessions (Vista, XP, use Google for others), then initiate a Remote Desktop session to 127.0.0.2, you can run as a completely different user on your local system, enabling you to do whatever you would like without having to switch between users.

For me, I normally run as a non-administrative user, but initiate a Remote Desktop session as an Administrator whenever I need to run an administrative task. But, you can do the opposite just as easily.

palswim