本帖最后由 went 于 2022-1-26 20:39 编辑
47,49行自己改下
test.bat, ansi编码- #&cls&@cd /d "%~dp0" & powershell -c "Get-Content '%~0' | Out-String | Invoke-Expression" &pause&exit
- $xml_Template=@'
- <?xml version="1.0"?>
- <WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
- <name>WIFI_NAME</name>
- <SSIDConfig>
- <SSID>
- <hex>WIFI_NAME_HEX</hex>
- <name>WIFI_NAME</name>
- </SSID>
- </SSIDConfig>
- <connectionType>ESS</connectionType>
- <connectionMode>manual</connectionMode>
- <MSM>
- <security>
- <authEncryption>
- <authentication>WPA2PSK</authentication>
- <encryption>AES</encryption>
- <useOneX>false</useOneX>
- </authEncryption>
- <sharedKey>
- <keyType>passPhrase</keyType>
- <protected>false</protected>
- <keyMaterial>WIFI_KEY</keyMaterial>
- </sharedKey>
- </security>
- </MSM>
- <MacRandomization xmlns="http://www.microsoft.com/networking/WLAN/profile/v3">
- <enableRandomization>false</enableRandomization>
- <randomizationSeed>634562794</randomizationSeed>
- </MacRandomization>
- </WLANProfile>
- '@
- #函数 更新或添加一个wifi配置
- function Add-WifiConfig($wifiName,$wifiKey,[switch]$connect){
- $wifiNameHex="";
- foreach ($each in [System.Text.Encoding]::UTF8.GetBytes($wifiName)) { $wifiNameHex+=("{0:x}" -f $each).ToUpper();}
- $xmlFile="WLAN-{0}.xml" -f $wifiName
- $xml=$xml_Template -replace "WIFI_NAME_HEX",$wifiNameHex -replace "WIFI_NAME",$wifiName -replace "WIFI_KEY",$wifiKey
- $xml | Out-File $xmlFile -Encoding utf8
- netsh wlan delete profile $wifiName >$null 2>$null
- netsh wlan add profile $xmlFile
- if($connect){ netsh wlan connect $wifiName }
- Remove-Item -LiteralPath $xmlFile
- }
-
- Add-WifiConfig -wifiName 'TP-LINK_0AE2' -wifiKey 'LLLL1234' -connect
-
- Add-WifiConfig -wifiName 'TP-LINK_5G_0AE2' -wifiKey 'LLLL1234'
复制代码
|