Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug a program that needs administrator rights under Windows 7

I'm running Visual Studio 2008 on Windows 7 64-bit. I'm logged in as administrator, and I'm running it as administrator, but the program I'm working on fails with access denied when I call a restricted API. If run the program from Explorer with "Run as Administrator" it works.

I was under the belief that Visual Studio 2008 debugs programs with whatever rights Visual Studio 2008 itself is running with. As it stands I can't debug my application due to this, and I'm at a loss as to what's going on.

like image 876
brian Avatar asked Jun 20 '10 19:06

brian


People also ask

How do I fix administrator permissions in Windows 7?

Select Start > Control Panel > Administrative Tools > Computer Management. In the Computer Management dialog, click on System Tools > Local Users and Groups > Users. Right-click on your user name and select Properties. In the properties dialog, select the Member Of tab and make sure it states "Administrator".

How do I debug as administrator in Visual Studio?

Run Visual Studio as an administratorOpen the Start menu, and scroll to Visual Studio. From the right-click or context menu of Visual Studio 2019 or Visual Studio 2022, select More > Run as administrator.

Why is the debug permission important for security in a Windows environment?

Developers who are debugging their own applications do not need this user privilege. Developers who are debugging system components or who are debugging remote components will need this user privilege. This user privilege provides complete access to sensitive and critical operating system components.


1 Answers

This works for Visual Studio 2012.

  • Create a manifest file: right click on the project and select "Add New Item", select "Application Manifest File". This will add a file named app.manifest to the project.
  • Edit manifest file: set attribute level for tag requestedExecutionLevel to requireAdministrator.

Now your program will always require admin privileges, wherever it is executed. If launched by Visual Studio debugger, it will prompt you for restarting Visual Studio as administrator, if needed.

like image 59
bluish Avatar answered Nov 02 '22 06:11

bluish