我为一家公司工作,他们希望我们创建一个脚本来重置所有网络设置,例如Windows 10更新“破坏”必须运行netsh winsock重置的网络。我们在商店创建了一个脚本,它很棒。
@echo off
goto check_Permissions
:check_Permissions
echo --------------------------------------------------------------------------------
echo This script was originally created by Adam, but modified and edited by Steven.
echo --------------------------------------------------------------------------------
echo Administrative permissions required. Detecting permissions...
net session >nul 2>&1
if %errorLevel% == 0 (
echo Success: Good job you did it right! Press any key to continue....
) else (
echo Failure: !!!!!!!!!!!DO NOT CONTINUE!!!!!!!!!!!! You are not using Administrative privlages. !!!!!!!!!!!DO NOT CONTINUE!!!!!!!!!!!!
)
pause >nul
echo Starting Netsh Dump...
start /wait netsh dump
echo Starting NBTSTAT...
start /wait nbtstat -R
echo Resetting Interface IP.
start /wait netsh int ip reset reset.log
echo Resetting Winsock...
start /wait netsh winsock reset
echo Resetting IPV4 settings...
start /wait netsh int ipv4 reset
echo Resetting IPV6 settings...
start /wait netsh int ipv6 reset
echo Resetting 6to4...
start /wait netsh int 6to4 reset all
echo Resetting HTTP Tunnel...
start /wait netsh int httpstunnel reset all
echo Resetting Port Proxy...
start /wait net int portproxy reset all
echo Releasing IP...
start /wait ipconfig /release
echo Renewing IP...
start /wait ipconfig /renew
echo Flushing DNS...
start /wait ipconfig /flushdns
echo Registering DNS...
start /wait ipconfig /registerdns
pause
通过并完成我们需要做的一切。前几天我的老板来了,问我们; “那么,如果他们的计算机上有静态IP甚至代理服务器,你就会怎么做,而你只是在没有获得这些信息的情况下删除了所有这些内容。同样,你所做的日志在哪里?每次运行此脚本时都应该记录脚本的功能。不只是在控制台上。'
好点...所以,我已经调整了一段时间,我无法将脚本输出到日志文件中,我已经尝试了>> Logs.txt,我试过> Logs.txt,我已经尝试了所有我能找到的东西,没有。我们还重写了脚本,使其更少集群......下面发布了。
@echo off
goto check_Permissions
:check_Permissions
echo --------------------------------------------------------------------------------
echo This script was originally created by Adam, but modified and edited by Steven.
echo --------------------------------------------------------------------------------
echo Administrative permissions required. Detecting permissions...
net session >nul 2>&1
if %errorLevel% == 0 (
echo Success: Good job you did it right! Press any key to continue....
) else (
echo Failure: !!!!!!!!!!!DO NOT CONTINUE!!!!!!!!!!!! You are not using Administrative privlages. !!!!!!!!!!!DO NOT CONTINUE!!!!!!!!!!!!
)
pause >nul
echo Starting Networking Reset...
netsh dump && nbtstat -R && netsh int ip reset reset.log && netsh winsock reset && nbtstat -R && netsh int ip reset && netsh int 6to4 reset all && netsh int httpstunnel reset all && net int portproxy reset all && ipconfig /flushdns
pause
基本上我只是希望它输出一个文件,说明所有操作都已完成,如果可能的话,扫描检测到在运行此脚本之前是否在网络中设置了静态IP //代理...
干杯, 连指手套。
答案 0 :(得分:0)
为了使其成为可点击的过程,我将2个bat文件串在一起。 2个蝙蝠如下,我会点击BatThatTriggersYourScript.bat
让它运行
BatThatTriggersYourScript.bat
CheckPermissions.bat > OurLog.log
CheckCheckPermissions.bat
All that code you already have
要在cmd行中手动执行,然后我会带走弦乐并每次都自己编写... yurk!
CheckCheckPermissions.bat > MyLog.log
作为旁注,>
会写入新文件,而>>
会附加到文件中。