管理员打开CMD窗口:
::开启移动热点(CMD 管理员)
cmd
powershell -Command "& { Add-Type -AssemblyName System.Runtime.WindowsRuntime; connectionProfile = \[Windows.Networking.Connectivity.NetworkInformation,Windows.Networking.Connectivity,ContentType=WindowsRuntime\]::GetInternetConnectionProfile(); tetheringManager = Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager,Windows.Networking.NetworkOperators,ContentType=WindowsRuntime::CreateFromConnectionProfile(connectionProfile); if (tetheringManager.TetheringOperationalState -ne 1) { asyncOp = tetheringManager.StartTetheringAsync(); $asyncOp.GetResults(); Write-Host '热点已开启' } else { Write-Host '热点已经是开启状态' } }"
::❌ 关闭移动热点(CMD 管理员)
cmd
powershell -Command "& { Add-Type -AssemblyName System.Runtime.WindowsRuntime; connectionProfile = \[Windows.Networking.Connectivity.NetworkInformation,Windows.Networking.Connectivity,ContentType=WindowsRuntime\]::GetInternetConnectionProfile(); tetheringManager = Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager,Windows.Networking.NetworkOperators,ContentType=WindowsRuntime::CreateFromConnectionProfile(connectionProfile); if (tetheringManager.TetheringOperationalState -eq 1) { asyncOp = tetheringManager.StopTetheringAsync(); $asyncOp.GetResults(); Write-Host '热点已关闭' } else { Write-Host '热点已经是关闭状态' } }"
::🔍 查询移动热点状态
cmd
powershell -Command "& { Add-Type -AssemblyName System.Runtime.WindowsRuntime; connectionProfile = \[Windows.Networking.Connectivity.NetworkInformation,Windows.Networking.Connectivity,ContentType=WindowsRuntime\]::GetInternetConnectionProfile(); tetheringManager = Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager,Windows.Networking.NetworkOperators,ContentType=WindowsRuntime::CreateFromConnectionProfile(connectionProfile); state = tetheringManager.TetheringOperationalState; if (state -eq 1) { '开启' } elseif ($state -eq 0) { '关闭' } else { '正在切换' } }"