I played with this for several days. We can get hwnd from IE, but not PID. Thus, the only way to see the HWnd for the PID is to call Win32API. So how to do it in VBS.
All computers have 4 VB.NET compilers installed. So, all we need is to write a com server that wraps GetWindowThreadProcessId.
In the script, write the following line to a text file. I reprogrammed another script for this, so the method names are stupid.
Imports System Imports System.Runtime.InteropServices Imports Microsoft.Win32 Imports System.Net.Mail Namespace SendMail <Guid("85B4AD6D-2E89-4869-9BBC-69E42738FCFC"), _ InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _ Public Interface _SendMail <DispId(1)> Function Send(ByVal hWnd As Integer) As Integer End Interface <Guid("C91EDEB2-3756-4893-905B-0E4E2150C7FD"), _ ClassInterface(ClassInterfaceType.None), _ ProgId("Scripting.SendMail")> Public Class SendMail Implements _SendMail Public SendMail() Public Declare Auto Function GetWindowThreadProcessId Lib "user32" Alias "GetWindowThreadProcessId" (ByVal hwnd As Integer, ByRef lpdwProcessId As Integer) As Integer Public Function Send(HWnd as Integer) As Integer Implements _SendMail.Send Dim X as Integer Dim M as Integer M=1 X=GetWindowThreadProcessID(HWnd,M) msgbox(X & " " & M & " " & HWnd & " " & Err.LastDllError) Send = M End Function End Class End Namespace
Then to compile WSHShell. Run the following hidden ways to fix commands.
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:library /out:"%userprofile%\desktop\sendmail\sendmail.dll" "%userprofile%\desktop\sendmail\sendmail.cls" /verbose "C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm" /codebase "%userprofile%\desktop\sendmail\sendmail.dll" /tlb:"%userprofile%\desktop\sendmail\sendmail.tlb" /v
Then for use in the script
Set x = CreateObject("Scripting.SendMail") Msgbox x.Send(&h1a013e)
Now I have generated a GUID for this purpose of creating com objects on the fly. Since they are in public code, you (AND ANY ELEMENT COPYING THIS) must destroy the object in your script. Run the Regasm command with / u. Or create new GUIDs.
source share