如何以管理员身份运行命令/脚本? [英] How do I run commands/scripts as an admin?

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

问题描述

您好,

我想在我的Command终端中运行一个名为scan.py的脚本。我键入

Hello,
I want to run a script called scan.py in my Command terminal. I type in

python scan.py

。我被告知,因为这不起作用,以管理员身份打开CMD窗口。所以窗口显示C:\ Windows \ system32>。

所以我的问题是,如何从那里运行我的脚本,而不必输入脚本的路径。



< b>我尝试了什么:



(我试过了,它会再次作为普通用户运行,而不是作为管理员)我应该移动文件进入目录system32?

运行

. 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

询问我输入管理员的密码,但我的所有建议都是(我尝试了自己的密码和只是按Enter键,两者都没有工作)错误。

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.

推荐答案

默认情况下,当您以管理员身份打开命令提示符时,当前目录设置为C: \ Windows \ system32。

你只需导航到目录( cd path\to\your\py\file ).py文件所在的位置并发出 python scan.py 命令(如总结python可执行文件在你的路径变量中,似乎就是这种情况。)



我应该把文件移到目录system32

在任何情况下都不应该在此目录中放置python脚本。更好地理解路径和命令的原理。



runas / user:administrator C:\ usersrs .... \cancan.py

你应该明白你必须直接启动 python 可执行文件,而不是.py脚本。

正确的命令最好是 runas / user:administrator pythonC:\ usersrs \\can.py

最好在引号之间包含脚本的完整路径,以确保它被理解为python可执行文件的参数。
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) where your .py file is located and issue the python scan.py command (assuming the python executable is in your path variable, which seems to be the case).

"Should I move the file in to the directory system32"
In no circumstance you should put a python script in this directory. Better understand the principle of paths and commands.

runas /user:administrator C:\users....\scan.py
You should understand that your have to launch the python executable, not the .py script directly.
Correct command would better be runas /user:administrator python "C:\users....\scan.py"
Better enclose the full path to the script between quotes, just to be sure it is understood as an argument to the python executable.


引用:

如何以管理员身份运行命令/脚本?

How do I run commands/scripts as an admin?



首先,为了以管理员身份运行应用程序,您需要拥有管理员权限或知道管理员用户名和密码。


First thing, in order to run an app as admin, you need to have admin rights or know an admin username and password.

引用:

所以我的问题是,如何运行从那里我的脚本,无需输入脚本的路径。

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



Shor回答,你没有。这就像发送邮件而不写地址。


Short answer, you don't. It is like sending a mail without writing the address.

Quote:

我应该将文件移到目录中吗system32?

Should I move the file in to the directory system32?



坏主意,这个目录受到保护,不适用于一般用途。最好移动到正确的目录,如:


Bad idea, this directory is protected and is not for general usage. It is better to move to correct directory like:

CD c:\myapp


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

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