在运行时检查高架状态 [英] Checking Elevated Status at run time

查看:77
本文介绍了在运行时检查高架状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

早些时候,我在旧程序中附加了清单文件,以在程序启动时提示UAC提升.虽然UAC确实会在程序启动时提示,但我目前无法获得程序中需要管理员身份的部分,以便在与我自己的计算机不同的计算机上正确输出.

为了正确调试此程序,我需要确保在将此应用程序转移到其他计算机时,它们实际上也在使用提升的管理员设置来运行我的程序.

我的问题是这样的:
在运行时,是否有一种相对简单的方法来确定程序是否在管理员设置较高的情况下运行?

如果我可以在另一台计算机上执行此检查,并且发现它正在以管理员身份运行,则可以确认问题出在我的代码上,而不是我的提示UAC进行提升的方法.我还将注意到我正在使用Windows7.

感谢您阅读本文!让我知道我的请求是否不清楚.

Hello everyone,

Earlier I attached a manifest file to my legacy program prompting UAC elevation on the start up of a program. While the UAC does prompt upon program start up, I am currently unable to get the section of my program requiring administrator status to properly output on computers separate from my own.

To properly debug this, I need to make sure that when I transfer this app to other computers, they are in fact also running my program with elevated administrator settings.

My question is this:
Is there a relatively simple way to, at run time, determine whether or not a program is running with elevated administrator settings?

If I can perform this check on another computer and it turns out that it is running with administrator status, I''ll be able to confirm that the issue is with my code and not my method of prompting the UAC for elevation. I will also note that I am working with Windows 7.

Thanks for reading this! Let me know if anything is unclear about my request.

推荐答案

可以在以下位置找到解决方案:
http://stackoverflow. com/questions/95912/how-can-i-detect-if-my-process-is-running-uac-elevated-or-not [ http://msdn.microsoft.com/zh-我们/library/windows/desktop/bb776463%28v=vs.85%29.aspx [ http://en.wikipedia.org/wiki/User_Account_Control [
The solution can be found there:
http://stackoverflow.com/questions/95912/how-can-i-detect-if-my-process-is-running-uac-elevated-or-not[^].



This is not the same as checking IsUserAnAdmin:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb776463%28v=vs.85%29.aspx[^].

This API merely checks up if the user is in the Administrator''s group. This is not what you need: to get elevated privileges, the user does not have to be in this group, and the privileges can be denied (via UAC) is the user is a member of this group.

I think this API was only useful for OS before Vista and Windows Server 2008 when UAC was introduced. For more information, please see:
http://en.wikipedia.org/wiki/User_Account_Control[^].

[END EDIT]

However, if you properly devise your manifest, you don''t really need to check it up. You can consider the functionality you need is already built in UAC in the following sense: if the user can get a requested privilege and confirm in the UAC confirmation dialog which appears automatically, the application will be executed, always with elevated privileges; in all other cases, if cannot be executed at all. I think if this functionality can be enough for your purpose, it''s always better.

If do understand that in certain cases you really need to check up the elevation in the application code. One simple example is: if it is granted the elevated privileges, you show full set of operations, if not, you hide or, better, disable some items from its UI. I just don''t see where you would need it in your case. You know better, of course.

—SA


这篇关于在运行时检查高架状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆