简体   繁体   English

创建一个以管理员身份运行的批处理文件,然后更新ip地址

[英]Create a Batch file that runs as administrator then renew the ip address

I have a domain network, and I am working on organizing the IP addresses on this domain using DHCP.我有一个域网络,我正在使用 DHCP 组织这个域上的 IP 地址。 Sometimes I need to shut down the server for some maintenance, then turn it on again, so when I do some end users get their IP's wrong, they just need to renew the addresses or press "Diagnose" in the local area connection status.有时我需要关闭服务器进行一些维护,然后再打开它,所以当我这样做时,一些最终用户的IP错误,他们只需要更新地址或在本地连接状态下按“诊断”即可。

I don't want to waste my time following up each host to diagnose their ip addresses to get them fixed, so I thought about a way to sum it all up in a double click, but google doesn't seem to be helping me this time.我不想浪费时间跟踪每个主机来诊断它们的 IP 地址以修复它们,所以我想了一种方法来通过双击来总结它,但谷歌似乎并没有帮助我时间。 The steps are the following (from the cmd / batch):步骤如下(来自cmd/batch):

1-enable administrative privileges 1-启用管理权限

2-ipconfid /release 2-ipconfid /release

3-ipconfig /renew 3-ipconfig /更新

4-convert the .txt into .bat 4-将 .txt 转换为 .bat

I am not sure that there is a step between 1 and 2, if it is mandatory to state the echo on/off.我不确定 1 和 2 之间是否有一个步骤,如果必须打开/关闭回声。 But what I want to be sure of is, when I open the cmd, then I want to enable the administrative rights to open the local area connection status, and then do the rest.但是我要确定的是,当我打开cmd时,然后我要启用管理权限以打开本地连接状态,然后再做剩下的。 As I could see that the code to open a file through admin rights is正如我所看到的,通过管理员权限打开文件的代码是

runas /profile /user:administrator “HERE THE NAME OF THE FILE TO OPEN”

But there is no need to open a specific file to edit them, so if you could help me find the way just to run as admin through the cmd and the rest is easy.但是不需要打开特定文件来编辑它们,所以如果你能帮我找到通过cmd以管理员身份运行的方法,剩下的就很容易了。

You can invoke Powershell from batch file to invoke another batch file to run under elevated privilege.您可以从批处理文件调用 Powershell 以调用另一个批处理文件以在提升的权限下运行。

Launcher.bat启动器.bat

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& { Start-Process "C:\Users\..\AdminProc.bat"  -Verb Runas}"

AdminProc.bat管理程序.bat

# Run any task that requires elevated privilege.
Net Stop "Sql Server (SQLEXPRESS)"

In second batch file you can run the ipconfig /release and ipconfig /renew with anyother command.在第二个批处理文件中,您可以使用任何其他ipconfig /release运行ipconfig /releaseipconfig /renew

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

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