Debug a program that needs administrator rights under Windows 7

后端 未结 6 646
旧时难觅i
旧时难觅i 2020-12-29 07:19

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 fa

相关标签:
6条回答
  • 2020-12-29 07:49

    It's best to run Visual Studio 2008 as administrator. Moreover, it's good to change your application's manifest settings to require administrator privileges. You will be prompted by the system to elevate to system administrator each time you start your application, and when running under Visual Studio 2008 the IDE will offer you the elevation before start of debugging.

    To change the setting, open project properties and go to Configuration PropertiesLinkerManifest fileUAC Execution Level.

    0 讨论(0)
  • 2020-12-29 07:51

    I had a case where I put in the

        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
    

    settings (described by another answer at this post)........and did not work.

    I found another tip (seen below)...and unchecking that option allowed my code to work.

    Try going into the project properties, and under the "debug" tab, uncheck "enable the Visual Studio hosting process" and see if that fixes your problem.

    (from https://social.msdn.microsoft.com/Forums/vstudio/en-US/b5c4da93-5d64-442e-af28-df6d10765538/debug-as-administrator?forum=vbgeneral)

    So I needed the app.manifest settings AND the "uncheck".

    0 讨论(0)
  • 2020-12-29 07:52

    My testing with Windows Vista and Visual Studio 2005 showed that when you use a host process, the behavior under the debugger depends only on how you launched Visual Studio and not on the manifest (or lack of manifest) of your application. When Visual Studio is launched elevated, the behavior depends only on the use (or not) of a host process, not on the manifest. This is probably still true with Windows 7 and Visual Studio 2008.

    Also, have you tried launching the application outside Visual Studio and using Attach to Process?

    0 讨论(0)
  • 2020-12-29 07:54

    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.

    0 讨论(0)
  • 2020-12-29 07:59

    Run Visual Studio 2008 as administrator.

    0 讨论(0)
  • 2020-12-29 08:07

    I found the answer. It turns out that it is, in fact, a manifest issue: by default if you have a manifest you need to set the appropriate administrator privilege.

    The default is asInvoker, but that doesn't work if you need elevated privileges; you instead have to set it to requireAdministrator in the manifest properties.

    0 讨论(0)
提交回复
热议问题