connect / disconnect wifi with same key(Windows 8.1) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Guill
Posts: 139
Joined: 09 Jun 2016, 22:00

connect / disconnect wifi with same key(Windows 8.1)

10 Nov 2017, 06:34

how can I do these actions?
(in windows 8.1)

f12:: ; two functions for 1 key

First time = connect wifi (on)

Second time = disconnect wifi (off)

third = first... and so on.

Thanks in advance!
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: connect / disconnect wifi with same key(Windows 8.1)

10 Nov 2017, 10:59

Keywords: toggle key + devcon
Good luck :)
Guill
Posts: 139
Joined: 09 Jun 2016, 22:00

Re: connect / disconnect wifi with same key(Windows 8.1)

10 Nov 2017, 14:10

I can't make the script by myself. My knowledge in AHK is beginner.
Please, help me writing it


(English is not my mother language. Sorry by mistakes)
teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: connect / disconnect wifi with same key(Windows 8.1)  Topic is solved

11 Nov 2017, 09:40

Guill, try:

Code: Select all

$F12:: ToggleWiFi()

ToggleWiFi()  {
   wmi := ComObjGet("winmgmts:")
   for adapter in wmi.ExecQuery("Select * from Win32_NetworkAdapter")
      if InStr(adapter.name, "wireless") && (interfaceName := adapter.NetConnectionID) && status := adapter.NetConnectionStatus
         break
      
   if (interfaceName = "" || status = "")  {
      MsgBox, Failed to get the interfaceName!
      return
   }
   if status not in 0,2   ; Disconnected = 0, Connected = 2
   {
      Loop  {
         Sleep, 500
         for adapter in wmi.ExecQuery("Select * from Win32_NetworkAdapter Where Index=" . adapter.Index)
            status := adapter.NetConnectionStatus
      } until status = 0 || status = 2 || (A_Index = 20 && failed := true)
      if failed  {
         MsgBox, Failed to get the status!
         return
      }
   }
   Run, % (A_IsAdmin ? "" : "*RunAs ") . "netsh.exe interface set interface name="""
                                       . interfaceName . """ admin="
                                       . (status = 0 ? "en" : "dis") . "abled",, Hide
}
Guill
Posts: 139
Joined: 09 Jun 2016, 22:00

Re: connect / disconnect wifi with same key(Windows 8.1)

11 Nov 2017, 13:51

Great!!

Thanks a lot, TeaDrinker!
Roboss_54
Posts: 1
Joined: 11 Jul 2020, 14:05

Re: connect / disconnect wifi with same key(Windows 8.1)

11 Jul 2020, 14:09

@teadrinker

Hello, I was using this code for a while but my PC crashed at some point and since then, I have not been able to connect to wifi, could you help out in any way?
teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: connect / disconnect wifi with same key(Windows 8.1)

11 Jul 2020, 16:08

Sorry, I can hardly help remotely. Make sure wifi is turned on via a physical switch, if any. Read this topic.
0ck
Posts: 1
Joined: 14 Jul 2021, 08:39

Re: connect / disconnect wifi with same key(Windows 8.1)

14 Jul 2021, 09:15

teadrinker wrote:
11 Nov 2017, 09:40
Guill, try:

Code: Select all

$F12:: ToggleWiFi()

ToggleWiFi()  {
   wmi := ComObjGet("winmgmts:")
   for adapter in wmi.ExecQuery("Select * from Win32_NetworkAdapter")
      if InStr(adapter.name, "wireless") && (interfaceName := adapter.NetConnectionID) && status := adapter.NetConnectionStatus
         break
      
   if (interfaceName = "" || status = "")  {
      MsgBox, Failed to get the interfaceName!
      return
   }
   if status not in 0,2   ; Disconnected = 0, Connected = 2
   {
      Loop  {
         Sleep, 500
         for adapter in wmi.ExecQuery("Select * from Win32_NetworkAdapter Where Index=" . adapter.Index)
            status := adapter.NetConnectionStatus
      } until status = 0 || status = 2 || (A_Index = 20 && failed := true)
      if failed  {
         MsgBox, Failed to get the status!
         return
      }
   }
   Run, % (A_IsAdmin ? "" : "*RunAs ") . "netsh.exe interface set interface name="""
                                       . interfaceName . """ admin="
                                       . (status = 0 ? "en" : "dis") . "abled",, Hide
}
Is it possible to disable it without having to connect to wifi, I mean disable the wifi driver with one f2 key without having to connect

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: aitaixy, Nerafius, RandomBoy and 192 guests