Windows 7下调试需要管理员权限的程序

发布于 2024-09-06 08:12:30 字数 236 浏览 6 评论 0原文

我在 Windows 7 64 位上运行 Visual Studio 2008。我以管理员身份登录,并以管理员身份运行它,但是当我调用受限 API 时,我正在处理的程序失败,访问被拒绝。如果使用“以管理员身份运行”从资源管理器运行该程序,则它可以工作。

我相信 Visual Studio 2008 可以使用 Visual Studio 2008 本身运行的任何权限来调试程序。就目前情况而言,我无法调试我的应用程序,因此我不知道发生了什么。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

雨落□心尘 2024-09-13 08:12:30

这适用于 Visual Studio 2012。

  • 创建清单文件:右键单击项目并选择“添加新项”,然后选择“应用程序清单文件”。这会将名为 app.manifest 的文件添加到项目中。
  • 编辑清单文件:将标签requestedExecutionLevel的属性level设置为requireAdministrator

现在,无论在何处执行,您的程序都将始终需要管理员权限。如果由 Visual Studio 调试器启动,它会提示您以管理员身份重新启动 Visual Studio(如果需要)。

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.

断念 2024-09-13 08:12:30

最好以管理员身份运行 Visual Studio 2008。此外,最好将应用程序的清单设置更改为需要管理员权限。每次启动应用程序时,系统都会提示您提升为系统管理员,并且在 Visual Studio 2008 下运行时,IDE 会在开始调试之前为您提供提升权限。

要更改设置,请打开项目属性并转到配置属性链接器清单文件UAC 执行级别

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.

り繁华旳梦境 2024-09-13 08:12:30

我找到了答案。事实证明,这实际上是一个清单问题:默认情况下,如果您有清单,则需要设置适当的管理员权限。

默认值为 asInvoker,但如果您需要提升权限,则该设置不起作用;您必须在清单属性中将其设置为 requireAdministrator

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.

反差帅 2024-09-13 08:12:30

以管理员身份运行 Visual Studio 2008。

Run Visual Studio 2008 as administrator.

别忘他 2024-09-13 08:12:30

我遇到过这样的情况:我输入了

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

设置(由本文的另一个答案描述)......并且不起作用。

我发现了另一个提示(见下文)...并且取消选中该选项可以让我的代码正常工作。

尝试进入项目属性,然后在“调试”选项卡下,
取消选中“启用 Visual Studio 托管进程”并查看是否
解决您的问题。

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

所以我需要app.manifest 设置和“取消选中”。

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".

飘然心甜 2024-09-13 08:12:30

我对 Windows Vista 和 Visual Studio 2005 的测试表明,当您使用主机进程时,调试器下的行为仅取决于您启动 Visual Studio 的方式,而不取决于应用程序的清单(或缺少清单)。当 Visual Studio 以提升权限启动时,行为仅取决于主机进程的使用(或不使用),而不取决于清单。对于 Windows 7 和 Visual Studio 2008 来说,情况可能仍然如此。

另外,您是否尝试过在 Visual Studio 外部启动应用程序并使用附加到进程

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文