|
发表于 2019-3-16 20:22
来自手机
|
显示全部楼层
本帖最后由 lss001 于 2019-3-19 10:37 编辑
Private Declare Function InternetGetConnectedState Lib "wininet.dll" _
(ByRef dwFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" Alias "InternetGetConnectedStateExA" _
(ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, ByVal dwNameLen As Long, ByVal dwReserved As Long) As Long
Sub pdwllj()
Dim LinkName As String * 128
If InternetGetConnectedState(0&, 0&) Then '判断网络是否连接
InternetGetConnectedStateEx 0, LinkName, 128, 0&
If Left$(LinkName, 3) = "LAN" Then '判断连接方式:LAN无线连接
'MsgBox "网络已连接"
Shell "cmd.exe /c netsh wlan Disconnect interface=""WLAN"""
'断开连接//其中WLAN为接口名称
ShellExecute 0, "runas", "cmd.exe", _
"/c netsh interface set interface name=""WLAN"" DISABLED", 0, 0 '关闭接口
End If
Else
'MsgBox "网络未连接"
ShellExecute 0, "runas", "cmd.exe", _
"/c netsh interface set interface name=""WLAN"" ENABLED", 0, 0 '打开接口
Application.Wait Now + TimeValue("00:00:01")
Shell "cmd.exe /c netsh wlan connect name=""wifi-name"""
'连接WIFI//其中wifi-name为wifi名称
End If
End Sub |
|