7

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:

enter image description here

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

enter image description here

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

enter image description here

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?

Miguel Angelo
  • 23,796
  • 16
  • 59
  • 82
  • What about turning your user account control privileges down for the Windows user you're running as? or take away admin privileges temporarily for that user (which would require a log off/log on cycle to take effect)? – rory.ap Feb 13 '17 at 20:23
  • I'll try that... just a minute, since I have to learn how to do that. Thanks! – Miguel Angelo Feb 13 '17 at 20:26
  • did you look at [this](https://msdn.microsoft.com/en-us/library/aa289173(v=vs.71).aspx) – Chandan Rai Feb 13 '17 at 20:27
  • Yes, I have... when not in administrative mode, the app does not run for long enough for me to attach the debuger. Also, older versions of VS seemed to run without admin rights, whereas VS 2015 does not. – Miguel Angelo Feb 13 '17 at 20:48
  • Changing UAC settings didn't work. It just asks for elevation before opening. – Miguel Angelo Feb 13 '17 at 20:54
  • It is not very clear why VS is prompting for elevation, it shouldn't. Try logging out, log back in using the non-admin account. Start VS and when it prompts then allow it to elevate. Might be necessary to setup stuff. Exit VS and start it again, hopefully it now no longer prompts and you can debug. Docs [are here](https://msdn.microsoft.com/en-us/library/jj662724.aspx). – Hans Passant Feb 13 '17 at 21:54
  • Use Process Monitor to find out whether it starts or not. If it starts and immediately exists, then it likely crashes. In that case, see http://stackoverflow.com/questions/24874027/how-do-i-take-a-good-crash-dump-for-net, get a crash dump and analyze that one. – Thomas Weller Feb 13 '17 at 22:43
  • @HansPassant - That did work. I had to login to the other account and run VS there. It didn't work to just start using `Run as different user` from my main account... then I thought that Windows 10 might be forcing it to start as Administrator... and this was indeed the problem. Windows 10 has a tool that can be accessed through the context menu of shortcuts called "Troubleshoot compatibility". This can be used to set the program to always run as admin. And I remember doing this to one shortcut and naming it `vs-admin`... but it didn't affect that specific shortcut... – Miguel Angelo Feb 13 '17 at 23:47
  • ... it affected all of the Visual Studio instances. But I never noticed it, until now. I didn't know it would affect all instances, and worse yet, I forgot completely that one day I did that. – Miguel Angelo Feb 13 '17 at 23:49
  • @ThomasWeller It was running. I ran it once resulting in a crash window that said the program had stopped working. It's not consistent though. Even throwing an exception (here at least) sometimes results in a crash window, and sometimes is completely silent, as if nothing had happened. But the problem is solved now. I'll leave an answer explaining what happened, so that other trapped people like me (smart people that cause their own problems and then forget, haha) can remember of their own actions and have a chance to undo it. – Miguel Angelo Feb 13 '17 at 23:55
  • @ Miguel Angelo, what about this issue? Would you please share the latest information here? – Jack Zhai Feb 16 '17 at 03:20
  • @JackZhai-MSFT The issue is resolved. I had to run the "Troubleshoot compatibility" and use the button "Try recommended settings" to undo the administrator always on option. Then I changed my "vs-admin" shortcut the correct way: through the properties window, going to Advanced Properties and selecting Run as administrator... only for that shortcut. – Miguel Angelo Feb 17 '17 at 17:12
  • @Miguel Angelo, if so, would you please mark helpful reply as the answer? If no one help, you could share your comment as the answer, and mark it, it would help other community members who meet the same issue research and find the answer easily if you could mark the answer. Have a nice day:) – Jack Zhai Feb 20 '17 at 01:59
  • I have yet to find a solution to this. In my case, what is happening is that Visual Studio 2022 is trying to modify settings in IIS (not IIS Express) installed on my local box. Visual Studio needs elevated permissions to update settings in IIS, start/stop the application pool, create remove virtual directories and application pools, and other management tasks. – Scott Forbes Jun 09 '22 at 16:59

6 Answers6

3

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.

Martin Schneider
  • 14,263
  • 7
  • 55
  • 58
  • I tried this and it did not solve my problem. Visual Studio is requiring elevated permissions so it can access management features in IIS (not express), in my case. I am trying to debug a problem that happens when an application runs under IIS, but does not happen in IIS Express. – Scott Forbes Jun 09 '22 at 17:02
  • This works if the account for which you are logged in is also an admin. In my case, our organization does not want us to be local admins on our machines in our "normal" accounts so they decided if we need to elevate to do something as an admin, we use a separate account. The problem is, then, if I elevate using a different account, visual studio runs under a different profile, and my plugins, settings, and licenses are all out the window. – Scott Forbes Jun 10 '22 at 13:29
2

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. Shortcut properties

Chris Bartlett
  • 312
  • 1
  • 11
  • I have only needed that checkbox checked when debugging an application using iis. Windows services have not needed elevated permissions and neither did a desktop application. What is your application doing that needs elevated permissions? I would start there. Visual Studio does not need admin rights to debug a base vanilla application. – Chris Bartlett Feb 13 '17 at 21:02
  • That's the problem... I don't know, some 3rd party lib needs admin privileges... and I just cannot debug to discover which one is it. – Miguel Angelo Feb 13 '17 at 21:04
  • My app is desktop, Windows Forms. – Miguel Angelo Feb 13 '17 at 21:06
  • When you do that, your VS opens without that "(Administrator)" in the title bar? I was unable to make that happen here. – Miguel Angelo Feb 13 '17 at 21:08
  • Honestly, it has been a long time since I have run VS 2015 not in admin mode. I just went back and checked on a windows service that I maintain and tried running in not in admin mode and debugged it without any issue. It did not prompt me to elevate the credentials. – Chris Bartlett Feb 13 '17 at 21:42
2

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 e.g. 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.

vidstige
  • 12,492
  • 9
  • 66
  • 110
1

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

Community
  • 1
  • 1
Jack Zhai
  • 6,230
  • 1
  • 12
  • 20
1

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. enter image description here

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

enter image description here

Ali Faraz
  • 31
  • 1
  • 5
0

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.

Pistoolirapu
  • 89
  • 1
  • 3