WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: spl on July 07, 2026, 07:31:01 AM

Title: In Case anyone is listening
Post by: spl on July 07, 2026, 07:31:01 AM
Yeah, I know this could be done with pure WB, but couldn't resist a PS one-liner with multi pipeline. Uses my std_out function to display current port listeners.
;Get Port Listeners
;Stan Littlefield 7/8/2026
;========================================================================================================================
Gosub udfs
file = Dirscript():"listeners.txt"
If fileexist(file) Then filedelete(file)
args = "Get-NetTCPConnection -State Listen | Select-Object -Property LocalPort, State, @{name='ProcessID';expression={(Get-Process -Id $_.OwningProcess). ID}}, @{name='ProcessName';expression={(Get-Process -Id $_.OwningProcess). Path}} | Sort-Object LocalPort"
cmd="Powershell"
msg='Display Port Listeners'
BoxOpen("Running...",cmd:" ":args:@LF:"PLEASE WAIT...MAY TAKE SOME TIME")
TimeDelay(3)
vals = Get_stdout()
Fileput(file,vals)
If FileExist(file) Then Run("notepad.exe",file)
Exit
;======================================================================
:udfs
#DefineSubroutine Get_stdout()
ObjectClrOption("useany","System")
objInfo = ObjectClrNew("System.Diagnostics.ProcessStartInfo")
Output=""
timeOut = ObjectType("I2",5000)
objInfo.FileName = cmd
objInfo.RedirectStandardError = ObjectType("BOOL",@TRUE)
objInfo.RedirectStandardOutput = ObjectType("BOOL",@TRUE)
objInfo.UseShellExecute = ObjectType("BOOL",@FALSE)
objInfo.CreateNoWindow = ObjectType("BOOL",@TRUE)
objInfo.Arguments = args
oProcess = ObjectClrNew("System.Diagnostics.Process")
oProcess.StartInfo = objInfo
BoxShut()
oProcess.Start()
oProcess.WaitForExit(timeout)
STDOUT = oProcess.StandardOutput.ReadToEnd()
STDERR = oProcess.StandardError.ReadToEnd()
Output = Output:STDOUT:@CRLF
;If STDERR<>""
;   Output = Output:"STDERR:":STDERR:@CRLF
;Endif
oProcess = 0
objInfo = 0

Return (Output)
#EndSubroutine
Return
;==========================================================
Title: Re: In Case anyone is listening
Post by: td on July 08, 2026, 07:55:01 AM
Ping
Title: Re: In Case anyone is listening
Post by: kdmoyers on July 09, 2026, 04:26:05 AM
This reminds me of a similar problem, only for the keyboard instead of port listeners.

Does anyone know of something that tells all the things that are trapping keys in the system? I've got so many hot keys defined, intentionally and unintentionally, that it's become a mess.
Title: Re: In Case anyone is listening
Post by: td on July 09, 2026, 07:46:51 AM
Of course, finding all the hot keys on a system can be a challenge because it is not a stationary target. There are global hot keys, desktop shortcut hotkeys, and several flavors of application hotkeys that may or may not be active only when the application has the input focus.

As I am sure you already know, the ShortcutInfo function can give you the hotkey combination associated with a desktop shortcut. Several freeware programs purported to find all active hotkeys. ActiveHotkey is one but I have never tried it.  Another application I have never used can be found on GitHub:

https://github.com/wikimint/winshortcuts

I think there are also COM or .Net based objects you could use to write your own WIL script to get at the global system shortcuts. I haven't tried that either.