C# 2005 控制台应用程序始终需要提升的权限

发布于 2024-08-12 12:12:09 字数 193 浏览 2 评论 0原文

我正在尝试在 Windows Vista 下使用 C# 2005 Express 版本构建自动化应用程序。问题是,每当我尝试运行此应用程序时,无论是从 IDE 还是在 Vista 下直接编译的可执行文件,它都会要求提升管理员权限,但相同的可执行文件通常在 XP 下运行!

我无法理解这个问题是否是由于清单或其他原因造成的......

谢谢,

I am trying to build an automation application in C# 2005 express edition under windows vista. Problem is, Whenever I try to run this application, either from IDE or directly compiled executable under vista, it asks for elevated admin privileges, same executable runs under XP normally though!

I'm unable to understand if this problem due to manifest or something else...

Thanks,

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

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

发布评论

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

评论(3

掩饰不了的爱 2024-08-19 12:12:09

首先,我会更新到2008 Express; 2005 Express 不再可供下载,但 2008 Express 除了为您提供 3.0/3.5 的优点外,仍然可以针对 .NET 2.0。而且它仍然是免费的。事实上,2010年快车即将来临!特别是,您会发现越来越难找到能够回答 2005 Express IDE 特定问题的人,仅仅是因为很少有人仍然安装 2005 Express。


添加应用程序清单文件(通过 IDE) - 它将显示为 app.manifest;它应该添加(默认情况下):

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

哪个(IIRC)应该有帮助 - 但是a:应用程序从哪里运行,b:它是做什么的? (它是否尝试编辑注册表等)。

Firstly, I would update to 2008 Express; 2005 Express is no longer available for download, but 2008 Express can still target .NET 2.0, in addition to giving you 3.0/3.5 goodness. And it is still free. Actually, 2010 Express is just around the corner! In particular, you'll find it increasingly hard to find people who can answer 2005 Express IDE-specific issues, simply because few people have 2005 Express still installed.


Add an application manifest file (via the IDE) - it will appear as app.manifest; it should add (by default):

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

Which should (IIRC) help - but a: where is the app running from, and b: what does it do? (does it try to edit the registry, etc).

是你 2024-08-19 12:12:09

除了 Marc 的回答之外:如果可执行文件的名称中包含“setup”或“install”,则无论清单如何,UAC 都会要求管理员权限。唯一的解决方法是将 .exe 重命名为不包含这些关键字的名称。

编辑:“更新”也是这样的关键字。另请参阅这篇有关 UAC 的 Technet 文章

Additionally to Marc's answer: If the executable has i.e. 'setup' or 'install' as part of it's name, the UAC asks for admin privileges regardless of a manifest. The only work around that is to rename the .exe to something that does not contain these keywords.

Edit: 'Update' is such a keyword too. Please see also this Technet article about UAC.

巨坚强 2024-08-19 12:12:09

如果您的应用程序尝试执行需要提升权限的操作(例如写入 Program Files 文件夹或注册表的某些区域),则需要请求提升权限,否则将会失败。在 XP 下,它根本不会要求提升;如果它没有运行所需的权限,它就会失败(但通常人们在 XP 下使用管理权限运行,所以这通常不是什么问题)

要在现有答案中添加一个“陷阱”:
如果您使用 .exe 上的文件属性(“兼容性”选项卡)强制其“以管理员身份运行”,则它在运行时将始终要求提升权限。不直观的是,这会永久应用于路径名,因此即使您删除 .exe 并安装新的,“作为管理员”设置仍然适用!您必须专门打开属性并禁用该属性才能再次将其删除。

If your application attempts to do things that require elevated privileges (e.g. write to the Program Files folder or some areas of the registry), it will need to ask for elevation or it'll fail. Under XP it won't ask for elevation at all; it'll just fail if it doesn't have the permissions it needs to run (but usually people run with administrative privileges under XP, so this isn't often a problem)

To add one "gotcha" to the existing answers:
If you use the file properties (Compatibility tab) on your .exe to force it to "run as administrator", it will always ask for elevation when it is run. Unintuitively, this is applied permanently to the pathname, so even if you delete the .exe and install a new one, the "as admin" setting will still apply! You have to specifically open the properties and disable that property to remove it again.

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