Tools/Linux_reinstall/Windows/SetupComplete.bat

58 lines
1.9 KiB
Batchfile
Raw Normal View History

2023-07-02 15:12:01 +08:00
@echo off
2023-10-13 16:12:45 +08:00
set setipv4mode=on
set setipv6mode=on
2023-10-13 16:21:32 +08:00
::ipv4 Static
2023-07-04 23:50:23 +08:00
set staticip=IPv4
2023-10-13 16:21:32 +08:00
::ipv4 Subnet
2023-07-02 15:12:01 +08:00
set subnetmask=actualIp4Subnet
2023-10-13 16:21:32 +08:00
::ipv4 Gateway
2023-07-04 23:50:23 +08:00
set gateways=GATE
2023-10-13 16:21:32 +08:00
::ipv4 Dns
2023-07-02 15:12:01 +08:00
set dnsserver1=ipDNS1
set dnsserver2=ipDNS2
2023-10-13 16:12:45 +08:00
2023-10-13 16:21:32 +08:00
::ipv6 Static
2023-10-13 16:12:45 +08:00
set staticip6=ip6Addr
2023-10-13 16:21:32 +08:00
::ipv6 Subnet
2023-10-13 16:12:45 +08:00
set subnetmask6=actualIp6Prefix
2023-10-13 16:21:32 +08:00
::ipv6 Gateway
2023-10-13 16:12:45 +08:00
set gateways6=ip6Gate
2023-10-13 16:21:32 +08:00
::ipv6 Dns
2023-10-13 16:12:45 +08:00
set dns6server1=ip6DNS1
set dns6server2=ip6DNS2
::Find Network Adapter Name
for /f "tokens=6-8" %%i in ('netsh interface ip show int ^| findstr /v /i "disconnected loopback vmware" ^| findstr /n ^^^^ ^| findstr "^[4]"') do set interfaceName=%%i %%j %%k
2023-07-05 04:06:52 +08:00
::Expand system partition
set systemDisk=%SystemDrive:~0,1%
for /f "tokens=2" %%a in ('echo list vol ^| diskpart ^| findstr "\<%systemDisk%\>"') do (echo select disk 0 & echo select vol %%a & echo extend) | diskpart
2023-07-02 15:12:01 +08:00
2023-10-13 16:21:32 +08:00
:: Write ipv4 static configs
2023-10-13 16:12:45 +08:00
echo; %setipv4mode% | find "on" && goto:enable || goto:disable
2023-07-02 15:12:01 +08:00
:enable
wmic nicconfig where ipenabled=true call enablestatic(%staticip%),(%subnetmask%)
2023-10-13 16:21:32 +08:00
::Using ipv4 of local server as a temporary "gateway" to make sure all of static ipv4 configs can be recognized by network service.
2023-08-21 19:56:51 +08:00
wmic nicconfig where ipenabled=true call setgateways(%staticip%)
2023-08-21 20:35:40 +08:00
::Replace temporary gateway to an actual one.
2023-07-02 15:12:01 +08:00
wmic nicconfig where ipenabled=true call setgateways(%gateways%)
2023-07-05 01:03:38 +08:00
wmic nicconfig where ipenabled=true call setdnsserversearchorder(%dnsserver1%,%dnsserver2%)
2023-10-13 16:12:45 +08:00
:disable
2023-10-13 16:21:32 +08:00
:: Write ipv6 static configs
2023-10-13 16:12:45 +08:00
echo; %setipv6mode% | find "on" && goto:enable || goto:disable
:enable
netsh interface ipv6 add address "%interfaceName%" %staticip6%/%subnetmask6%
netsh interface ipv6 add route "::/0" "%interfaceName%" %gateways6%
netsh interface ipv6 add dnsservers "%interfaceName%" %dns6server1%
netsh interface ipv6 add dnsservers "%interfaceName%" %dns6server2%
netsh interface set interface "%interfaceName%" disabled
netsh interface set interface "%interfaceName%" enabled
2023-07-05 01:24:08 +08:00
del %0
2023-07-05 04:06:52 +08:00
pause
2023-07-02 15:12:01 +08:00
:disable
2023-07-05 04:06:52 +08:00
del %0
pause