这是用来封装系统进入桌面时自动连接对应WIFI的,我们这 有2个WIFI,想自动保存到WIFI连接列表,求高手合并,虽然分别运行也是可以的,但还是想用一个做到,谢谢- @echo off
- powershell -c "Get-Content -LiteralPath '%~0' | Select-Object -Skip 3 | Out-String | Invoke-Expression"
- pause&goto b_bat
- $wifiName="WIFI1"; # WIFI NAME
- $wifiKey="88888888"; # WIFI PASSWORD
- $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>
- "@
- $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 2>$null
- netsh wlan add profile $xmlFile
- netsh wlan connect $wifiName
- Remove-Item -LiteralPath $xmlFile
复制代码
- @echo off
- powershell -c "Get-Content -LiteralPath '%~0' | Select-Object -Skip 3 | Out-String | Invoke-Expression"
- pause&exit
- $wifiName="WIFI2"; # WIFI NAME
- $wifiKey="88888888"; # WIFI PASSWORD
- $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>
- "@
- $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 2>$null
- netsh wlan add profile $xmlFile
- netsh wlan connect $wifiName
- Remove-Item -LiteralPath $xmlFile
复制代码
|