【问题标题】:Require program to run as admin要求程序以管理员身份运行
【发布时间】: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 属性作为答案,我会接受它

标签: c windows-7 admin


【解决方案1】:

我建议如果你设置可执行文件的属性和权限,使其只能由管理员运行,就可以解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-10
    • 2011-12-29
    • 1970-01-01
    • 1970-01-01
    • 2013-05-31
    相关资源
    最近更新 更多