python3管理员身份调用程序,如何以管理员身份运行命令/脚本?

在Windows中,当以管理员身份打开命令提示符时,默认目录为C:\Windows\System32。要运行位于其他位置的scan.py,首先使用`cd`命令导航到脚本所在目录,然后运行`python scan.py`。不应将脚本移动到System32目录,而应理解路径和命令的概念。正确使用`runas`命令的方式是`runas /user:administrator python "C:\users....\scan.py"`,确保Python解释器在PATH变量中,并且脚本路径用引号包围。
摘要由CSDN通过智能技术生成

Hello,

I want to run a script called scan.py in my Command terminal. I type inpython scan.py. I got told, since this is not working, to open the CMD window as admin. So the window shows me C:\Windows\system32>.

So my question is, how do I run my script from there, without having to type in the path to the script.

What I have tried:

(I tried that and it would run as a normal user again, not as admin) Should I move the file in to the directory system32?

Running "runas /user:administrator C:\users....\scan.py asks me for the password of the admin, but all of my suggestions were (I tried my own password and just hitting enter, both didn't work) wrong.

解决方案By default, when you open a command prompt as an administrator, the current directory is set to C:\Windows\System32.

You just have to navigate to the directory (cd path\to\your\py\file)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值