Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
617 views
in Technique[技术] by (71.8m points)

batch file - appactivate between multiple internet explorer instances

Is it possible to use wshshell.appactivate to switch between multiple internet explorer windows?

I am trying to write a script that will bring different instances of internet explorer in kiosk mode to the front. The end goal is to make it look like it's going from one web page to the next. I tried using wshshell.sendkey but it doesn't look smooth with the open webpage dialog popping up.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I played with this for a few days. We can get an hwnd from IE, but not a PID. So the only way I can see to match HWnd to PID is call a Win32API call. So how to do that in VBS.

All computers have 4 VB.NET compilers installed. So all we need do is write a com server that wraps GetWindowThreadProcessId.

In your script write out the following line to a text file. I repurposed a different script for this so method names are silly.

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 commands hidden fixing paths.

"C:WindowsMicrosoft.NETFrameworkv4.0.30319vbc.exe" /target:library /out:"%userprofile%desktopsendmailsendmail.dll" "%userprofile%desktopsendmailsendmail.cls" /verbose


"C:WindowsMicrosoft.NETFrameworkv4.0.30319
egasm" /codebase "%userprofile%desktopsendmailsendmail.dll" /tlb:"%userprofile%desktopsendmailsendmail.tlb" /v

Then to use in script

Set x = CreateObject("Scripting.SendMail")
Msgbox x.Send(&h1a013e)

Now I've generated the GUID's for this purpose of creating com objects on the fly. As they are in now public code you (AND ANYONE ELSE COPYING THIS) must destroy the object in your script. Run the Regasm command with /u. Or generate new GUIDs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...