专门的学业组的批处理,Win批管理开机自动安装

2019-12-03 04:25 来源:未知

Win批管理开机自动安装IP地址

自己负担的部门有那贰个台机器,重装完后急需还原原有配置,我曾接收过不菲格局:
1:手工改过,那条就不用说了
2:使用netsh dump +文件和 netsh -f +文件来校订,不过总体盘都格式化就没用.
今晚开什么特马查询,3:使用专项使用的转移ip地址的小程序,但要么必要手工来钦赐IP

 

谈起底,笔者想开如下办法:
1:首先落成:netsh interface ip 来更动IP
2:使用wmic computersystem 改良专业组
3:使用reg add 来改进机器名
4:因为订正机器名后要重启才生效,于是利用:reboot.inf 来重启
5:后来增添了新机器名和ip的安排,使用机器的种类号(联想机:wmic bios get SerialNumber卡塔尔来做机器名,ip地址最终1位使用随机
因为能够经过 wmic来读取连串号,那么我们能够用来登记本机的网络布局时,就方便多了.
6:最终将团结整理的IP地址等应者云集表放到了bat中,幸免bat调用其余文件.
7:完结地点效能后,作者就足以将该bat文件封装到gho文件里面,复苏重启完后就能够自行安装,笔者毫无做其他操作,顾客就能够使用.若是有必要,你能够加多施行完后自动删除本身.

@echo off     www.2cto.com  

不论什么事代码如下:(迎接大家持续优化和收拾卡塔尔(قطر‎

REM select=1,网卡IP将被设置成172.16.200.34,select=2,网卡IP将被设置成192.168.0.5 

复制代码 代码如下:

ping -n 2 192.168.0.254 && set select=2  || set select=1

@echo off & code by m13632750052
990991藏宝阁开奖记录,for /f "tokens=12 delims= " %%i in ('ipconfig/all^|find "Physical Address"') do set localmac=%%i
echo 通过MAC地址%localmac%查找对应的机器名
for /f "skip=90 tokens=1,2,3,4 delims= " %%i in (%~f0) do (
if [%%k]==[%localmac%] set Name=%%i
if [%%k]==[%localmac%] set IP=%%j
if [%%k]==[%localmac%] set MAC=%%k
if [%%k]==[%localmac%] set Workgroup=%%l
set mask=255.255.0.0
set gway=168.30.1.233
set dns=168.1.4.147
set dns2=168.1.6.243
)
echo 彰显查找结果 code by cn-dos breakme
if defined Name (echo %Name% %IP% %mac% %Workgroup%) else (goto newset)
:Enterset
for /l %%i in (3,-1,0卡塔尔(قطر‎ do ping -n 2 127.0.0.%%i>nul && @echo. %%i s 后修正机器名……

REM 获取网卡名称

reg add "HKEY_CURRENT_USERSoftwareMicrosoftWindowsShellNoRoam" /v @ /t REG_SZ /d "%Name%" /f
reg add "HKLMSYSTEMCurrentControlSetControlComputerNameComputerName" /v "ComputerName" /t REG_SZ /d "%Name%" /f
reg add "HKLMSYSTEMCurrentControlSetControlComputerNameActiveComputerName" /v "ComputerName" /t REG_SZ /d "%Name%" /f
reg add "HKLMSYSTEMCurrentControlSetServicesEventlog" /v "ComputerName" /t REG_SZ /d "%Name%" /f
reg add "HKLMSYSTEMCurrentControlSetControlComputerNameComputerName" /v "ComputerName" /t REG_SZ /d "%Name%" /f
reg add "HKLMSYSTEMCurrentControlSetServicesTcpipParameters" /v "NV Hostname" /t REG_SZ /d "%Name%" /f
reg add "HKLMSYSTEMCurrentControlSetServicesTcpipParameters" /v "Hostname" /t REG_SZ /d "%Name%" /f

for /f "skip=4 tokens=3* delims= " %%i in ('ipconfig') do (

echo 刷新注册表
if exist c:winnt (secedit /refreshpolicy machine_policy /enforce) else (gpupdate /force)

 set adapter=%%i

echo 改过职业组
wmic computersystem where Name="%Name%" call JoinDomainOrWorkgroup Name="%Workgroup%"
wmic computersystem where Name="%ComputerName%" call JoinDomainOrWorkgroup Name="%Workgroup%"

 goto out

echo 修改IP
::查找MAC所对应的连年名称
for /f "tokens=1,2,3,4,5,6 delims=-" %%A in ("%MAC%") do set MacWMIC=%%A:%%B:%%C:%%D:%%E:%%F
for /f "skip=2 tokens=2* delims==" %%A in ('WMIC NIC WHERE "MACAddress='%MacWMIC%' AND NetConnectionID!=NULL" GET NetConnectionID /value') do set "ConnName=%%A"
if not defined ConnName set ConnName="本地连接"
netsh interface ip set address name="%ConnName%" source=static addr=%IP% mask=%mask%
netsh interface ip set address name="%ConnName%" gateway=%gway% gwmetric=0
netsh interface ip set dns name="%ConnName%" source=static addr=%dns% register=PRIMARY
netsh interface ip add dns name="%ConnName%" addr=%dns2% index=2
netsh interface ip set wins name="%ConnName%" source=static addr=none

)

echo arp绑定 %IP% %MAC%
arp -d
arp -s %IP% %MAC%
echo arp绑定网关 %gway%,假若网络堵塞,将选取暗中同意网关的MAC:00-00-5e-00-01-01
ping -n 2 %gway%>nul 2>nul
if [%ERRORLEVEL%]==[1] (set GateMac=00-00-5e-00-01-01) else (
for /f "skip=3 tokens=2" %%H in ('arp -a %gway%') do set GateMac=%%H
)
cmd /c arp -s %gway% %GateMac%

 

for /l %%i in (3,-1,0卡塔尔(قطر‎ do ping -n 2 127.0.0.%%i>nul && @echo. %%i s 后重启计算机……
setlocal
cd/d %temp%
echo [version] > reboot.inf
set inf=InstallHinfSection DefaultInstall
echo signature=$chicago$ >> reboot.inf
echo [defaultinstall] >> reboot.inf
rundll32 setupapi,%inf% 1 %temp%reboot.inf
del reboot.inf
EXIT

:out

:newset
echo 您的机器也许是新机器,须要手工业输入ip
for /f "tokens=1,2 delims==" %%i in ('wmic bios get SerialNumber /value^|find "="') do set Name=%%j
if not defined Name set /p Name=请输入新机械的名字
echo 机器名:%Name%
call :select "Physical Address" "mac"
echo mac :%mac%
set /a aa=%random%%%9
set IP=168.30.7.1%aa%
set mask=255.255.0.0
set gway=168.30.1.233
set dns=168.1.4.147
set dns2=168.1.6.243
set Workgroup=vga00l
echo IP 配置: %ip% %mask% %gway% %dns% %dns2% %Workgroup%
for /l %%i in (5,-1,0卡塔尔(英语:State of Qatar) do ping -n 2 127.0.0.%%i>nul && @echo. %%i s 后改良机器名……
goto Enterset

set adapter=%adapter::=%

:select
for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| findstr /i /c:%1') do if not "!%~2!" == "" set "%~2=%%i"
GOTO :eof

if %select%==1 (

 netsh int ip set address name="%adapter%" static 172.16.200.34 255.255.255.0 172.16.200.1 1

 netsh int ip set dns name="%adapter%" static 202.102.224.68 primary

 netsh int ip add dns name="%adapter%" 202.102.227.68 index=2

) else (

 netsh int ip set address name="%adapter%" static 192.168.0.5 255.255.255.0 192.168.0.254 1

)

 

echo 设置完结,按大肆键退出!

pause >nul 2>nul  

@echo off www.2cto.com REM select=1,网卡IP将被设置成172.16.200.34,select=2,网卡IP将被设置成192.168.0.5 ping -n 2 192.168....

TAG标签:
版权声明:本文由990888藏宝阁发布于关于计算机,转载请注明出处:专门的学业组的批处理,Win批管理开机自动安装