Windows 7下调试需要管理员权限的程序
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这适用于 Visual Studio 2012。
requestedExecutionLevel
的属性level
设置为requireAdministrator
。现在,无论在何处执行,您的程序都将始终需要管理员权限。如果由 Visual Studio 调试器启动,它会提示您以管理员身份重新启动 Visual Studio(如果需要)。
This works for Visual Studio 2012.
level
for tagrequestedExecutionLevel
torequireAdministrator
.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.
最好以管理员身份运行 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 Properties → Linker → Manifest file → UAC Execution Level.
我找到了答案。事实证明,这实际上是一个清单问题:默认情况下,如果您有清单,则需要设置适当的管理员权限。
默认值为
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 torequireAdministrator
in the manifest properties.以管理员身份运行 Visual Studio 2008。
Run Visual Studio 2008 as administrator.
我遇到过这样的情况:我输入了
设置(由本文的另一个答案描述)......并且不起作用。
我发现了另一个提示(见下文)...并且取消选中该选项可以让我的代码正常工作。
(来自 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
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.
(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".
我对 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?