简体   繁体   English

创建批处理文件以管理员身份在命令提示符下运行命令

[英]Creating a batch file to run a command on command prompt as administrator

I would like to create a batch file in order to run a windows command on command prompt as administrator whenever I start the PC. 我想创建一个批处理文件,以便在每次启动PC时以管理员身份在命令提示符下运行Windows命令。

For example I would like to run the command prompt as administrator and run the command Ping 8.8.8.8 on startup of windows. 例如,我想以管理员身份运行命令提示符,并在Windows启动时运行命令Ping 8.8.8.8

Can anyone please explain the full procedures with snapshots? 任何人都可以用快照解释完整的过程吗?

Thanks in advance M. Ashraful Haque 在此先感谢M. Ashraful Haque

You could try something like this create another batch file and add the below command it will run it as the user you specify 您可以尝试执行类似的操作,创建另一个批处理文件并添加以下命令,它将以您指定的用户身份运行

@echo off
Runas /env /user:PCNAME\Administrator test.bat

Or 要么

you can add your batch file to the Scheduled task list link below on how to do this. 您可以将批处理文件添加到下面的“计划任务列表”链接中,以了解如何执行此操作。 In Scheduled Task you can set what account to use and when it should run. 在计划任务中,您可以设置要使用的帐户以及应在何时运行。

Change when it runs in create task go to Triggers tab click new and change "Begin the task" to start up 更改在创建任务中运行的时间,转到“触发器”选项卡,单击“新建”,然后更改“开始任务”以启动

Create Scheduled Task 创建计划任务

First with SCHTASKS you can create add a batch file to run as a service and you can give the top privileges , example: 首先,使用SCHTASKS可以创建添加批处理文件以作为服务运行,并且可以赋予最高特权,例如:

SCHTASKS /Create /TN "Ping My Web Host" /SC HOURLY /TR "C:\services\pinghost.cmd" /RU username /RP password /RL HIGHEST

Here's the documentation documentation and here 这是文档文档这里

And this you'd wanted to read this . 这你会想读这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM