SHARE
TWEET

ahk internet toggle

mordecai86 Jan 1st, 2020 518 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $F12:: ToggleWiFi()
  2.  
  3. ToggleWiFi()  {
  4.    wmi := ComObjGet("winmgmts:")
  5.    for adapter in wmi.ExecQuery("Select * from Win32_NetworkAdapter")
  6.       if InStr(adapter.name, "Realtek PCIe GBE Family Controller") && (interfaceName := adapter.NetConnectionID) && status := adapter.NetConnectionStatus
  7.          break
  8.      
  9.    if (interfaceName = "" || status = "")  {
  10.       MsgBox, Failed to get the interfaceName!
  11.       return
  12.    }
  13.    if status not in 0,2   ; Disconnected = 0, Connected = 2
  14.    {
  15.       Loop  {
  16.          Sleep, 500
  17.          for adapter in wmi.ExecQuery("Select * from Win32_NetworkAdapter Where Index=" . adapter.Index)
  18.             status := adapter.NetConnectionStatus
  19.       } until status = 0 || status = 2 || (A_Index = 20 && failed := true)
  20.       if failed  {
  21.          MsgBox, Failed to get the status!
  22.          return
  23.       }
  24.    }
  25.    Run, % (A_IsAdmin ? "" : "*RunAs ") . "netsh.exe interface set interface name="""
  26.                                        . interfaceName . """ admin="
  27.                                        . (status = 0 ? "en" : "dis") . "abled",, Hide
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top