Skip to content

Instantly share code, notes, and snippets.

@vayn
Created March 20, 2022 20:41
Show Gist options
  • Save vayn/a0bb5513bf2ac9aadb4bb2695575ded2 to your computer and use it in GitHub Desktop.
Save vayn/a0bb5513bf2ac9aadb4bb2695575ded2 to your computer and use it in GitHub Desktop.
strCmd = "%COMSPEC% /c ping 192.0.2.1 -n 1 -w 1000 >nul"
Set shell = CreateObject("WScript.Shell")
shell.Run strCmd, 0, 1
WScript.Echo("Foreground window title: " & vbCrLf & GetForeWindowCaption())
Function GetForeWindowCaption()
Const WM_GETTEXT = &HD
Set DX = CreateObject("DynamicWrapperX")
DX.Register "user32", "GetForegroundWindow", "f=s", "r=l"
DX.Register "user32", "SendMessage", "i=huuS", "f=s", "r=l"
Title = Space(100)
res = DX.SendMessage(DX.GetForegroundWindow(), WM_GETTEXT, 100, Title)
GetForeWindowCaption = Title
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment