Get Connected Network Name

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
DataLife
Posts: 460
Joined: 29 Sep 2013, 19:52

Get Connected Network Name

31 Aug 2023, 20:55

The following code used to work properly for one of my users. Something changed and now it does not retrieve the correct name for his internet connection. It still works properly on windows 10 home and windows 10 pro on my test computers.

My user has Windows 11 pro, I do not.

The issue is that he has 2 networks with the same name, at work "PGNET" and at home "pgnet"

The following code retrieves PGNET when the wireless is connected to pgnet at home.

Code: Select all

CLSID_NetworkListManager := "{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"
NLM_ENUM_NETWORK_CONNECTED := 1
NetworkListManager := ComObjCreate(CLSID_NetworkListManager)
for NetWork in NetworkListManager.GetNetworks(NLM_ENUM_NETWORK_CONNECTED)
 {
  INetWork := ComObjValue(NetWork)
  DllCall(NumGet(NumGet(INetWork + 0) + A_PtrSize*9), "Ptr", INetWork, "PtrP", pWStr)
  NetworkName := StrGet(pWStr, "UTF-16") ;get network name
  DllCall("OleAut32\SysFreeString", "Ptr", pWStr)
 }
 MsgBox % NetworkName
I created 2 hotspots with the same name "PHONE" and "phone". The above code retrieves the proper network no matter how many times I switch back and forth on windows 10 home and pro.

Can someone that has windows 11 pro try the above code and see if it retrieves the correct network after you have connected to both networks with the same name but different case?

Other than his computer being windows 11 pro, I can not imagine why this code would not work properly.
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
DataLife
Posts: 460
Joined: 29 Sep 2013, 19:52

Re: Get Connected Network Name

01 Sep 2023, 15:23

The issue is not Windows 11 related.

I found when going from Wired connection to wireless connection this would remember the wired connection when connected to a wireless connection.

Code: Select all

DllCall(NumGet(NumGet(INetWork + 0) + A_PtrSize*9), "Ptr", INetWork, "PtrP", pWStr)
I changed the PtrSize to 7 and it works properly.

Code: Select all

DllCall(NumGet(NumGet(INetWork + 0) + A_PtrSize*7), "Ptr", INetWork, "PtrP", pWStr)
Can anyone explain why?
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Hugh Jars, peter_ahk, Pianist and 359 guests