visual-studiocmdmsbuildelevationbuild-events

Visual Studio 2015 builds failing because pre-build event 'requires elevation'


I have a very simple VS2015 solution with one project. The project does not have any source code, but it has a pre-build event defined. The pre-build event was originally invoking a batch file pb.bat, but I have since changed it to REM pb.bat so that it only executes the REM statement.

Every time I try building, I get the following error message:

Microsoft.Common.CurrentVersion.targets(1250,5): error MSB6003: The specified task executable "cmd.exe" could not be run. The requested operation requires elevation

I should note that UAC is disabled. This is driving me crazy! I have even tried reinstalling Visual Studio, in case the targets files or something else was corrupt with the installation, but the problem persists. If I run Visual Studio as an Administrator, the build works, but I don't want to have to run it like that forever!


Solution

  • I had completely forgotten about this! A couple of days ago I had configured cmd.exe to always run as an Administrator. This was done in the registry:

    [HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
    "C:\\Windows\\System32\\cmd.exe"="RUNASADMIN"
    

    The problem went away as soon as I reverted the change. I am making a note of this, as I am bound to hit the same problem in the future.