【发布时间】:2017-08-23 05:44:49
【问题描述】:
如何使用 C 检查我的程序是否在 Windows 7 系统上以管理员身份运行?
我可以批量执行以下操作:
whoami /groups | findstr /b /c:"Mandatory Label\High Mandatory Level" | findstr /c:"Enabled group" > nul: && set IS_ELEVATED=1
if %IS_ELEVATED%==0 (
set /p _="You need to run Utilis as administrator, run with admin cmd. Press enter to exit..
)
这将检查当前用户是否是管理员。如何在 C 中实现相同的概念?
【问题讨论】:
-
通过设置可执行文件的属性使其只能由管理员运行?
-
@WeatherVane 这可行,有没有办法从程序本身中做到这一点?
-
抱歉,没试过。
-
@WeatherVane 很好,发布 exec 属性作为答案,我会接受它