在Windows中以管理员身份运行python脚本 [英] Run python script as admin in windows

查看:1733
本文介绍了在Windows中以管理员身份运行python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本来删除和替换 C:\Windows 目录中的某些文件。

I have a script that removes and substitute some files in C:\Windows directory.

我以管理员身份启动命令行,然后在其中启动python脚本。当脚本尝试从 C:\Windows 中删除​​文件时,出现 WindowsError错误5

I start command line as admin then I start my python script in it. And when the script tries to remove files from C:\Windows, I get WindowsError error 5.

我该如何解决?

可能的解决方案:
实际上,我试图修改仅具有TrustedInstaller用户所有特权的文件,因此我使用了 https:// github。 com / jschicht / RunAsTI 运行python脚本。

Possible solution: Actually I was trying to modify files which has all privileges only for TrustedInstaller user, so I used this https://github.com/jschicht/RunAsTI to run python script.

推荐答案

WindowsError错误5 在您没有执行任何操作的系统管理员特权时发生。

您可以尝试使用Windows cmd命令 runas 强制脚本以admin特权运行。

尝试如下操作:< br>

WindowsError error 5 occurs when you have no System Administrator privileges to perform action.
You can try to force script to run with admin priveleges with Windows cmd command runas.
Try something like this:

runas /user:administrator_account path_to_script

只需将Administrator_account替换为在计算机上具有特权的帐户名即可。此外,此命令还将提示您输入密码(如果帐户进行了一次设置)。
有关此命令的更多信息,您可以阅读这里。

Just replace administrator_account with account name that has privileges on your computer. Also this command will prompt for password (if account has one setup). For more information about this command you can read here.

这篇关于在Windows中以管理员身份运行python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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