topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday May 26, 2020, 7:41 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Wanted: tray icon that shows if wifi connection is 2.4 or 5 GHz  (Read 1463 times)

brotherS

  • Master of Good Ideas
  • Honorary Member
  • Joined in 2005
  • **
  • Posts: 2,192
    • View Profile
    • Donate to Member
Hello,

does anyone here know an app who offers this? Maybe even with customizable colors (one for 2.4 and another for 5 GHz)? I've tried Google but couldn't find one...

highend01

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 175
    • View Profile
    • Donate to Member
Re: Wanted: tray icon that shows if wifi connection is 2.4 or 5 GHz
« Reply #1 on: January 15, 2020, 03:26 PM »
Write a simple .ahk script which executes
netsh wlan show interfaces
and parses the content afterwards.

Regarding capturing the cmd output, e.g.: https://autohotkey.c...5-stdouttovar/page-7

If Channel is 1-14 you're on 2,4 GHz and if it's 36+ (both values depend on country, look at e.g. https://en.wikipedia...(802.11a/h/j/n/ac/ax)
you're on 5 GHz.

~15 lines of code, 3 16x16 px .png / .ico files (e.g. grey = no wifi connection, green = 2.4 GHz, red = 5 GHz, or whatever you'd prefer)...

Works at least on Win 10...
« Last Edit: January 15, 2020, 05:28 PM by highend01 »

brotherS

  • Master of Good Ideas
  • Honorary Member
  • Joined in 2005
  • **
  • Posts: 2,192
    • View Profile
    • Donate to Member
Re: Wanted: tray icon that shows if wifi connection is 2.4 or 5 GHz
« Reply #2 on: January 16, 2020, 02:43 AM »
Works at least on Win 10...
Are you willing to share that working code? I have zero experience with that side of AutoHotkey...

highend01

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 175
    • View Profile
    • Donate to Member
Re: Wanted: tray icon that shows if wifi connection is 2.4 or 5 GHz
« Reply #3 on: January 16, 2020, 04:22 AM »

#NoEnv
#SingleInstance force
#Persistent

Gosub, Check
SetTimer, Check, 5000
return


Check:
result := Runret("cmd /c netsh wlan show interfaces")
RegExMatch(result, "im)channel\s+:\s*(?P<Channel>\d{1,3})", match)

If (matchChannel >= 1 && matchChannel <= 14)
Menu, Tray, Icon, %A_ScriptDir%\_green.png
Else If (matchChannel >= 34)
Menu, Tray, Icon, %A_ScriptDir%\_red.png
Else
Menu, Tray, Icon, %A_ScriptDir%\_grey.png

return


; http://www.autohotkey.com/board/topic/15455-stdouttovar/page-7
Runret(cmd, params="") {
; Assemble command + parameters
cmd := (params) ? cmd . " " . params : cmd

DllCall("CreatePipe", "Ptr*", hStdInRd , "Ptr*", hStdInWr , "Uint", 0, "Uint", 0)
DllCall("CreatePipe", "Ptr*", hStdOutRd, "Ptr*", hStdOutWr, "Uint", 0, "Uint", 0)
DllCall("SetHandleInformation", "Ptr", hStdInRd , "Uint", 1, "Uint", 1)
DllCall("SetHandleInformation", "Ptr", hStdOutWr, "Uint", 1, "Uint", 1)

; Fill a StartupInfo structure
if A_PtrSize = 4 ; We're on a 32-bit system
{
VarSetCapacity(pi, 16, 0)
sisize := VarSetCapacity(si, 68, 0)
NumPut(sisize,    si,  0, "UInt")
NumPut(0x100,     si, 44, "UInt")
NumPut(hStdInRd , si, 56, "Ptr") ; stdin
NumPut(hStdOutWr, si, 60, "Ptr") ; stdout
NumPut(hStdOutWr, si, 64, "Ptr") ; stderr
}
else if A_PtrSize = 8 ; We're on a 64-bit system
{
VarSetCapacity(pi, 24, 0)
sisize := VarSetCapacity(si, 96, 0)
NumPut(sisize,    si,  0, "UInt")
NumPut(0x100,     si, 60, "UInt")
NumPut(hStdInRd , si, 80, "Ptr") ; stdin
NumPut(hStdOutWr, si, 88, "Ptr") ; stdout
NumPut(hStdOutWr, si, 96, "Ptr") ; stderr
}

DllCall("CreateProcess" , "Uint", 0 ; Application Name
, "Ptr", &cmd ; Command Line
, "Uint", 0 ; Process Attributes
, "Uint", 0 ; Thread Attributes
, "Int", True ; Inherit Handles
, "Uint", 0x08000000 ; Creation Flags (0x08000000 = Suppress console window)
, "Uint", 0 ; Environment
, "Uint", 0 ; Current Directory
, "Ptr", &si ; Startup Info
, "Ptr", &pi) ; Process Information

DllCall("CloseHandle", "Ptr", NumGet(pi, 0))
DllCall("CloseHandle", "Ptr", NumGet(pi, A_PtrSize))
DllCall("CloseHandle", "Ptr", hStdOutWr)
DllCall("CloseHandle", "Ptr", hStdInRd)
DllCall("CloseHandle", "Ptr", hStdInWr)

VarSetCapacity(temp, 4095)
size := 0
Loop
{
result := DllCall("Kernel32.dll\ReadFile", "Uint", hStdOutRd, "Ptr", &temp, "Uint", 4095, "UintP", size, "Uint", 0)
if (result = "0")
break
else
output := output . StrGet(&temp, size, "CP850")
}
DllCall("CloseHandle", "Ptr", hStdOutRd)
return output
}

anandcoral

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 690
    • View Profile
    • App, to help you : Overlap Wallpaper, Park Cursor Aside, Stick A Note, Merge CSV and Text and many more.
    • Donate to Member
Re: Wanted: tray icon that shows if wifi connection is 2.4 or 5 GHz
« Reply #4 on: January 16, 2020, 05:17 AM »
great highend01  :Thmbsup:

Attached are the pngs, if required by anyone  :)

_red.png  _green.png  _grey.png

[EDIT] pngs gives error so attached ico files. Please change .png to .ico in ahk by highend01.



Regards,

Anand
« Last Edit: January 16, 2020, 05:27 AM by anandcoral »

highend01

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 175
    • View Profile
    • Donate to Member
Re: Wanted: tray icon that shows if wifi connection is 2.4 or 5 GHz
« Reply #5 on: January 16, 2020, 06:32 AM »
pngs gives error so attached ico files
The three .png files I'm using here are working perfectly fine...

anandcoral

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 690
    • View Profile
    • App, to help you : Overlap Wallpaper, Park Cursor Aside, Stick A Note, Merge CSV and Text and many more.
    • Donate to Member
Re: Wanted: tray icon that shows if wifi connection is 2.4 or 5 GHz
« Reply #6 on: January 16, 2020, 06:39 AM »
pngs gives error so attached ico files
The three .png files I'm using here are working perfectly fine...
I got this error

---------------------------
ahk tray icon that shows if wifi connection is 2.4 or 5 GHz.ahk
---------------------------
Error:  Can't load icon.

Specifically: E:\TempE\_grey.png

Line#
016: RegExMatch(result, "im)channel\s+:\s*(?P<Channel>\d{1,3})", match) 
018: if (matchChannel >= 1 && matchChannel <= 14) 
019: Menu,Tray,Icon,%A_ScriptDir%\_green.png
020: Else
020: if (matchChannel >= 34) 
021: Menu,Tray,Icon,%A_ScriptDir%\_red.png
022: Else
---> 023: Menu,Tray,Icon,%A_ScriptDir%\_grey.png
025: Return
029: {
031: cmd := (params) ? cmd . " " . params : cmd
033: DllCall("CreatePipe", "Ptr*", hStdInRd , "Ptr*", hStdInWr , "Uint", 0, "Uint", 0) 
034: DllCall("CreatePipe", "Ptr*", hStdOutRd, "Ptr*", hStdOutWr, "Uint", 0, "Uint", 0) 
035: DllCall("SetHandleInformation", "Ptr", hStdInRd , "Uint", 1, "Uint", 1) 
036: DllCall("SetHandleInformation", "Ptr", hStdOutWr, "Uint", 1, "Uint", 1) 

The current thread will exit.
---------------------------
OK   
---------------------------

Changing .png to .ico and using the ico files, it worked correctly. Maybe autohotkey version problem. There is no problem/error in your code.
Thanks for it.

Regards,

Anand

highend01

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 175
    • View Profile
    • Donate to Member
Re: Wanted: tray icon that shows if wifi connection is 2.4 or 5 GHz
« Reply #7 on: January 16, 2020, 06:53 AM »
The .png files you've attached to your previous post are working fine as well.

AHK v1.1.32.00

anandcoral

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 690
    • View Profile
    • App, to help you : Overlap Wallpaper, Park Cursor Aside, Stick A Note, Merge CSV and Text and many more.
    • Donate to Member
Re: Wanted: tray icon that shows if wifi connection is 2.4 or 5 GHz
« Reply #8 on: January 16, 2020, 12:03 PM »
The .png files you've attached to your previous post are working fine as well.

AHK v1.1.32.00
Ahh..mine is still older version 1.0.48.05
Looks like I need to upgrade, as I am missing many new features of it.

Regards,

Anand

anandcoral

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 690
    • View Profile
    • App, to help you : Overlap Wallpaper, Park Cursor Aside, Stick A Note, Merge CSV and Text and many more.
    • Donate to Member
Re: Wanted: tray icon that shows if wifi connection is 2.4 or 5 GHz
« Reply #9 on: January 17, 2020, 04:24 AM »
Updated Autohotkey to Version 1.1.32.00, and it is using png files as tray icon now  :D

Regards,

Anand

brotherS

  • Master of Good Ideas
  • Honorary Member
  • Joined in 2005
  • **
  • Posts: 2,192
    • View Profile
    • Donate to Member
Re: Wanted: tray icon that shows if wifi connection is 2.4 or 5 GHz
« Reply #10 on: January 17, 2020, 04:35 AM »
Thanks, highend01! And thanks for the info, anandcoral. :)