简体   繁体   中英

Debug application without admin rights in Visual Studio

I have an application that is intended to run without admin rights, but it fails in that scenario. I tried to run my app as administrator, and it runs. But that's not what I want.

What I want is a way to debug my application without administrator privileges, so that I can determine what is causing it to fail when running as a normal user... so that I at least know what is the cause, and possibly make it in a way that runs without admin rights.

Whenever I run Visual Studio 2015, it starts with Administrator privileges. No way to get rid of that (Administrator) in title bar:

在此处输入图片说明

I have tried runas /netonly /user:User devenv.exe to no avail:

在此处输入图片说明

If I try to run VS2015 under another more restricted account, it say that it needs Administrative privileges, and does not run:

在此处输入图片说明

Clicking "Cancel the task ad return to Visual Studio" won't return to VS, instead it will close.

The problem is that when I run my application without admin privileges it does not open. No messages. Nothing. But when I try to debug it inside Visual Studio it runs... because VS itself only runs as administrator.

Is there a way to debug without admin rights?

From one day to the other I faced the same issue with VS 2019.

  1. The "Run as administrator" checkbox was everywhere (every shortcut and exe file) unchecked
  2. Also in the "Troubleshoot compatibility" dialog "The program requires additional permissions" was unchecked .

The solution

Change ownership of the devenv.exe ( C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\IDE\\devenv.exe ):

  1. Right-click devenv.exe > Properties
  2. Go to the Security tab.
  3. Click Advanced . (there, Administrator was the owner of the file, in my case)
  4. So click Change to edit the owner of the file to your user account.

Now Visual Studio is launched without administrator rights and therefore also the debugging.

Unfortunately, this must be done after every update.

If you right click on the shortcut and select properties, then select the shortcut tab, there is an advanced button. Click that and you can then select he application to not start in admin mode. Also, be aware that if you are using iis you will need VS to be running in admin mode to debug. 快捷方式属性

There is something wrong with your Visual Studio installation. It can for sure run without admin. However, you can work around this.

  1. Launch your app as you want, but not from within Visual Studio, but navigate to the built .exe and eg double-click it.
  2. Use the Attach to process option in Visual Studio to attach to the process.

If your app fails very quickly this will of course not work, and you will instead need to look into your Visual Studio setup.

So the issue is that it still opened the VS as the admin even if you just open the blank VS IDE in your side, am I right?

Please make sure that you don't enable "The program requires additional permissions" under Troubleshoot compatibility or the property settings for the VS IDE shortcut or the devenv.exe:

https://blog.devoworx.net/2016/01/06/this-task-requires-the-application-to-have-elevated-permissions/

https://superuser.com/questions/547810/how-to-turn-off-always-run-as-administrator-windows-8

For additional info around this case.

I have quite restricted IT systems at work and normally my VS was starting without admin privileges. However, to allow me to install updates etc. I made a request to put my .exe in the list of softwares starting with admin privileges. That happened. Good for updating.

Therefore, I assume, there is not way how I may temporary start my VS without admin privileges.

I faced similar issue when tried to use Outlook Interop from console app with following code:

        Outlook.Application application = null;

        // Check whether there is an Outlook process running.
        if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
        {
            // If so, use the GetActiveObject method to obtain the process and cast it to an Application object.
            application = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
        }
        else
        {

            // If not, create a new instance of Outlook and log on to the default profile.
            application = new Outlook.Application();
        }

        // Return the Outlook Application object.
        return application;

I received following error when VS (and therefore my console app) was started with admin privileges but the Outlook was not:

System.Runtime.InteropServices.COMException (0x800401E3): Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))

Then I tried to start the same code from debug folder directly by running .exe file and it worked properly.

Thanks for good hints.

It's an old post but I want to add my input as the solution in my case was a bit different and might help someone.

I had similar issue with Visual Studio 2019 using windows 10. When i pressed F5(debug), 'This task requires the application to have elevated permissions' message was prompted. 在此处输入图片说明

I tried many solutions recommended but didn't work for me. The issue was iisexpress.exe 'IIS Express Worker Process' setting was set to 'Run as Administrator'. I was trying to fix port binding issue and made some changes which i forgot to undo.

 Run project in Visual Studio with Administrator permission and then Open task manager > Processes > expand Visual Studio 2019 node > right click on 'IIS Express Worker Process'> properties> Compatibility > uncheck Run as Administrator option

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM