【问题标题】:Cannot import ctypes for checking admin privileges on Windows platform无法导入 ctypes 以检查 Windows 平台上的管理员权限
【发布时间】:2022-01-23 14:49:31
【问题描述】:

堆栈溢出程序员你好,

我正在尝试为我的代码导入我的库,但是每当我在 PyCharm 上执行我的代码时,我都会收到一个错误:

File "C:\Users\USER\projectextinguish\venv\lib\site-packages\command_runner\elevate.py", line 49, in <module>
raise ImportError(
ImportError: Cannot import ctypes for checking admin privileges on Windows plaform

有人知道我如何导入 ctypes 吗?

我不知道该怎么办。

代码:

import os   #self explainitory
from command_runner.elevate import elevate


def admin():
  elevate(mainfirewall)



   admin()   # executes admin function

   def mainfirewall ():
os.system("netsh advfirewall set allprofiles state off")              # disables firewall

mainfirewall()         #executes firewall function

【问题讨论】:

  • 问题不在于导入ctypes。问题更可能是您的代码尝试使用command_runner.elevate,而您的当前用户没有管理员权限。您应该显示完整的堆栈跟踪,包括您自己的代码。
  • @SergeBallesta 你的愿望就是我的命令
  • @SergeBallesta 我在这里要做的是提升,我想我应该将文档链接到库:pypi.org/project/command-runner

标签: python uac penetration-tools


【解决方案1】:

我可以通过安装command_runner 和不 安装pywin32 来重现您的错误消息的最后一部分。我得到了:

Traceback (most recent call last):
  File "C:\Users\...\ess\venv\lib\site-packages\command_runner\elevate.py", line 43, in <module>
    import win32event  # monitor process
ModuleNotFoundError: No module named 'win32event'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\...\ess\venv\lib\site-packages\command_runner\elevate.py", line 49, in <module>
    raise ImportError(
ImportError: Cannot import ctypes for checking admin privileges on Windows platform.

stacktrace 的第一部分给出了原因:pywin32 包需要有 win32event 模块。

如何修复:使用pip install pywin32 安装缺少的包

【讨论】:

  • 谢谢@Serge Ballesta 我打算给图书馆的作者发一封电子邮件,哈哈
猜你喜欢
  • 2010-11-04
  • 2017-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-19
  • 1970-01-01
相关资源
最近更新 更多