none
Have debugger run application as different user?

    Question

  • I find myself having issues when I push my applications out to testing because I'm not catching a lot of database permissioning issues in debug. The problem is that I write my SQL in Visual Studio and work on my application. I'm running VS as a user who has full access to the database because I need it to run queries. When I debug my application, I'd like to run it under a different user so that I can catch permissioning issues.

    How do other people deal with this issue?

    Wednesday, November 25, 2009 3:13 PM

Answers

  • Hi,

    Thanks for your post.

    I found a similar issue at: http://stackoverflow.com/questions/1287099/runas-a-different-user-when-debugging-in-visual-studio

    If you set the command line in debug external program, Vsual Studio will always attach to the cmd.exe process. It doesn't support attach to a spawned process. 

    In order to debug that process, I summarize a workaround which is similar with Lei's solution:
    1. Writing the following code at the beginning of your application
    System.Diagnostics.Debugger.Launch();
    2.  Run the following command in cmd console
    runas /savecred /user:OtherUser DebugTarget.Exe
    When the application starts, it will first ask for the user's password. After it runs to the debugger.launch code, windows will pop up a window to let you choose to use a new VS or existing on to debug the application.

    Hope it helps.

     

    Hongye Sun [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, November 26, 2009 3:40 AM
    Moderator

All replies

  • You can set infinite loop in your app and run it under aonther user, then attach debugger to the process

    also you can start visual studio with another user, and start debugging.
    Thursday, November 26, 2009 2:09 AM
  • Hi,

    Thanks for your post.

    I found a similar issue at: http://stackoverflow.com/questions/1287099/runas-a-different-user-when-debugging-in-visual-studio

    If you set the command line in debug external program, Vsual Studio will always attach to the cmd.exe process. It doesn't support attach to a spawned process. 

    In order to debug that process, I summarize a workaround which is similar with Lei's solution:
    1. Writing the following code at the beginning of your application
    System.Diagnostics.Debugger.Launch();
    2.  Run the following command in cmd console
    runas /savecred /user:OtherUser DebugTarget.Exe
    When the application starts, it will first ask for the user's password. After it runs to the debugger.launch code, windows will pop up a window to let you choose to use a new VS or existing on to debug the application.

    Hope it helps.

     

    Hongye Sun [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, November 26, 2009 3:40 AM
    Moderator
  • Please let me know if this issue is still not resolved. Thanks.

     

    Hongye Sun [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, December 10, 2009 1:58 AM
    Moderator
  • If you're on VS2010 you can then use VSCommands Pro to start debugging as a different user directly from IDE.
    Monday, September 13, 2010 10:41 PM