Short answer: You can’t. At least not without writing a COM wrapper for the relevant Windows API calls.
Can’t you just use AppActivate
and check the result?
Set oShell = CreateObject("WScript.Shell")
If oShell.AppActivate "Untitled - Notepad" Then
oShell.SendKeys "Hello, world!"
End If
Long answer: To get the active window title, you need to call the Windows API GetWindowText
function and pass the GetForegroundWindow()
handle. VBScript and Windows Script Host don’t support Windows API calls, so you’ll need to write a COM wrapper around these functions, that you can then use in your script. Here’re examples:
Get current active Window title in C
How do I get the title of the current active window using c#?