Appactivate between multiple instances of Internet explorer

Can I use wshshell.appactivate to switch between multiple Internet Explorer windows?

I am trying to write a script that will launch various instances of Internet Explorer in kiosk mode. The ultimate goal is to make it look like it is happening from one web page to another. I tried using wshshell.sendkey, but it does not look smooth when an open webpage dialog opens.

+1
source share
2 answers

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.

+1
source

You can list all windows explorer / browser.

From Help

Windows Method


Creates and returns a ShellWindows object. This object is a collection of all open windows that belong to the shell.

Syntax

 oWindows = Shell.Windows() 

Return value

ShellWindows object reference.

Examples

The following example uses Windows to retrieve a ShellWindows object and display the number of elements it contains. Proper use is shown for Microsoft JScript, Microsoft Visual Basic Scripting Edition (VBScript), and Visual Basic. VBScript:

Show example

 <script language="VBScript"> function fnShellWindowsVB() dim objShell dim objShellWindows set objShell = CreateObject("Shell.Application") set objShellWindows = objShell.Windows if (not objShellWindows is nothing) then alert(objShellWindows.Count) end if set objShellWindows = nothing set objShell = nothing end function </script> 

But I do not know how this will help if they do not have another title text. Appactivate is the only Windows scripting command available.

Appactivate also returns a value indicating whether it was activated or not. If you try to activate the active window, this will not work, since the window is already active.

You can perform process switching, but usually web pages are in the same process. AppActivate accepts PID

 Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * From Win32_Process") For Each objItem in colItems msgbox objItem.ProcessID & " " & objItem.Caption Next 
0
source

Source: https://habr.com/ru/post/1242306/


All Articles