Wait for a LAN connection

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Archimede
Posts: 464
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Wait for a LAN connection

Post by Archimede » 29 Jan 2023, 12:08

How is possible to wait for an activation of a net connection at a secific address?
I would like a function like the Command line
Netstat
but asynchronous, tha automatically active when a specific address and port begin active (I need to detect when a LAN remote control begin active, without a cyclic Netstat).
Thank you very much.

gmoises
Posts: 74
Joined: 18 Nov 2017, 16:43

Re: Wait for a LAN connection

Post by gmoises » 29 Jan 2023, 16:55

If you want to detect an RDC connection there is information here:
https://superuser.com/questions/1200200/how-to-properly-quit-from-a-remote-desktop-session-tsdiscon-now-logs-the-local

You can have a Timer to check for RDC frecuently:

Code: Select all

Thread("Interrupt", 0)												; Make all threads always-interruptible.
SetTimer("Check_RDC", 10000)										; every 10 segundos, look for RDC
Return

Check_RDC:
	RDC := SysGet(4096) 	; returns returns 0 when there is no RDC Connection
							; returns NonZero (tipically 1) when RDC is active
	If RDC
	{
		; here you do whats needed
	}
Return

SysGet(SubCommand) {			; from https://www.autohotkey.com/boards/viewtopic.php?f=37&t=29689
	Local OutputVar
	SysGet, OutputVar, %SubCommand%
	Return, OutputVar
}

Archimede
Posts: 464
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: Wait for a LAN connection

Post by Archimede » 29 Jan 2023, 18:39

:-(
I know the timer function.
I would like an asychronous function to activate ONLY when a specific connection at a specific address and port begins (like a Dll Api function).
I need to to detect if the number of the RDC is modified or if one or much RDC are changed.

Archimede
Posts: 464
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: Wait for a LAN connection

Post by Archimede » 31 Jan 2023, 10:01

Do you know if is possible to wait for an activation of a net connection at a specific address?
I would like a function like the Command line
Netstat
but asynchronous, tha automatically active when a specific address and port begin active (I need to detect when a LAN remote control begin active, without a cyclic Netstat).
I need to detect if and when one or more Remode Device Controller (or Remote Access) are active.
Thank you very much.


Archimede
Posts: 464
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: Wait for a LAN connection

Post by Archimede » 31 Jan 2023, 12:09

Thank you very much.
I no know C++, then I am no very able to understand all on the link.
Is there a simple way to detect any specific LAN open (or close) connection?

malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Wait for a LAN connection

Post by malcev » 31 Jan 2023, 12:14

Do not think that there is simple way.

Archimede
Posts: 464
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: Wait for a LAN connection

Post by Archimede » 03 Feb 2023, 19:48

Ok.
Do you know if there is an API way to wait for a specific lan connection?

malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Wait for a LAN connection

Post by malcev » 04 Feb 2023, 02:16

On my link it is api. It is not c++ code.
You can search forum for functions that are used on my link and try to build some code.
Also wmi has some event notification, but it works like You set timer within wmi and wmi with this timer checks if event occurs. (IMHO not best decision)
https://learn.microsoft.com/en-us/windows/win32/wmisdk/swbemsink

User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Wait for a LAN connection

Post by jNizM » 06 Feb 2023, 04:09

If you go for swbemsink you can take a look at these examples:
viewtopic.php?f=83&t=105171

Or this (but would have to be adapted to your needs):
viewtopic.php?f=83&t=104451
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Wait for a LAN connection

Post by malcev » 12 Feb 2023, 14:48

Now I understood topic starter question and think that it can be done with this api
https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtsregistersessionnotification

Post Reply

Return to “Ask for Help (v1)”