简体   繁体   中英

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. 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.

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. The steps are the following (from the cmd / batch):

1-enable administrative privileges

2-ipconfid /release

3-ipconfig /renew

4-convert the .txt into .bat

I am not sure that there is a step between 1 and 2, if it is mandatory to state the echo on/off. 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. 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.

You can invoke Powershell from batch file to invoke another batch file to run under elevated privilege.

Launcher.bat

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

AdminProc.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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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