Script opens infinite instances of Internet Explorer, without setting active window - vbscript

I wrote a vbscript program to automatically join Google Meet sessions, with the code that is required to enter the meet generated based on the date and time. Whenever I run the program, it opens in the background of the computer in infinite windows(repeatedly opening a new instance of Google Meet every second). The keystrokes that are supposed to be directed toward Internet Explorer are instead sent to whatever is active. The line of code that is supposed to make it the active window are not working: WshShell.AppActivate "Internet Explorer" I believe that this below section is what is causing problems. Any help is greatly appreciated!
option explicit
dim webbrowser, WshShell
set webbrowser = createobject("internetexplorer.application")
set WshShell = createobject("Wscript.Shell")
webbrowser.statusbar = false
webbrowser.menubar = false
webbrowser.toolbar = false
webbrowser.visible = true
webbrowser.navigate("https://meet.google.com/")
wscript.sleep(3000)
WshShell.AppActivate Internet Explorer
WshShell.sendkeys "{enter}"

I don't know why did you use sendkeys ?
You should write something like that :
Option explicit
dim webbrowser
set webbrowser = createobject("internetexplorer.application")
webbrowser.statusbar = false
webbrowser.menubar = false
webbrowser.toolbar = false
webbrowser.visible = true
webbrowser.navigate("https://meet.google.com/")
Do while webbrowser.readystate <> 4
wscript.sleep 200
Loop

Related

Quit all hidden/invisible windows

Sometimes I use the command ie.visible = False which hides the window even though it still exists.
How can I close all the hidden windows ?
My actual solution is to log out from my computer's session and log in again...there is probably a better way to do this.
I tried Set ie = Nothing or ie.Quit but it doesn't affect the hidden windows since when I count them with
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
they are still there.
Any ideas on how to do this?
I created a couple of hidden internet explorer windows and did a before and after count of the open internet explorer windows and the below code seems to work:
Public Sub CLOSE_HIDDEN_IE()
Dim IE As SHDocVw.InternetExplorer
Dim SH As SHDocVw.ShellWindows
Set SH = New SHDocVw.ShellWindows
For Each IE In SH
If IE.Visible = False Then
IE.Quit
End If
Next
Set IE = Nothing
Set SH = Nothing
End Sub
The code loops through the open internet explorer window and closes the ones which aren't visible.
Happy to help if you need anything.

Save a popup window to text using VBS

I have created a code that will open Internet Explorer, navigate to a site, prompt for credentials and a date range, and then save the data (theoretically) to a text file.
Everything works except for saving the data. When I click their export button, it pops up a new window that is untitled (so I can't focus on the window by name) and when I try to save it to a .txt file it saves the 1st webpage that is still focused, not the popup window.
How do I shift focus to the popup window/save the popup to a text file?
Unfortunately I can't provide much code, but here is the code I am using to save to a text file:
TEXT = objIE.Document.Body.InnerText
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile("Banorte.txt", 2, True)
ts.Write TEXT
ts.Close
Also, I don't have an option to download any software to help me with this. I am also not opposed to using a different language if need by, or call a separate script.
Thank you for taking a look!
------EDIT------
Here is some additional code, the site is banorte.com, this is the code that runs after I log in.
And by popup, I mean it opens up a new window in internet explorer, but it is not like a tab, that has a name and could be added to the parent window. It is a standalone.
objIE.Document.getElementsByName("btnEntrar").Item(0).Click
While objIE.Busy
WScript.Sleep 100
Wend
objIE.Document.getElementsByName("ctl00$Contentplaceholder1$btnConsultar").Item(0).Click
WScript.Sleep 5000
objIE.document.parentWindow.execScript "javascript:__doPostBack('ctl00$Contentplaceholder1$grdCuentasCheques$ctl02$ctl00','')"
BEGDATE= InputBox("Please enter the beginning date DD/MM/YYYY:","Please provide additional info.")
objIE.Document.getElementById("ctl00_Contentplaceholder1_ucPeriodoFechas_WucFechaInicial_txtFecha").value = BEGDATE
ENDDATE= InputBox("Please enter the ending date DD/MM/YYYY:","Please provide additional info.")
objIE.Document.getElementById("ctl00_Contentplaceholder1_ucPeriodoFechas_WucFechaFinal_txtFecha").value = ENDDATE
objIE.Document.getElementsByName("ctl00$Contentplaceholder1$btnConsultar").Item(0).Click
WScript.Sleep 2000
Issue is after this command:
objIE.Document.getElementsByName("ctl00$Contentplaceholder1$btnExportarSaldos").Item(0).Click
Do Until objIE.readystate = 4
WScript.Sleep 10
loop
TEXT = objIE.Document.Body.InnerText
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile("Banorte.txt", 2, True)
ts.Write TEXT
ts.Close
objIE.Navigate "https://nbem.banorte.com/NBXI/Corporativa/Cerrar.aspx"
ObjIE.quit

vbscript to auto detect open window and close it OR Google Apps Script to control form submit button

In the past I've used the script below to detect if an active window with the title "Remote Desktop" is or isn't active. If it isn't active the script will auto launch or make it active again.
Question: Is there a way to detect if a window is active and auto close it? I'm setting up a kiosk in chrome kiosk mode on a Windows 7 machine for our office. The main page launches a selected Google form in a pop-up window. The form confirmation page has the title "Thank You!" in the title bar. Is there a way for the script to auto detect this window and close it? This would be nice because the user would see that their response was submitted (for a second or two) but if they did not close the window it would not still be open when the next user goes to use the kiosk.
Another option might be if there is a way to use a Google script on the form to program the submit button to close the window. I'm not sure if that's possible.
Option Explicit
'On Error Resume Next
Dim objShell
Set objShell = CreateObject("WScript.Shell")
Do
If (objShell.AppActivate("Window Title Here") = False) Then
objShell.Run "mstsc.exe " & chr(34) & "c:\scripts\Remote Desktop.rdp" & chr(34)
WScript.Sleep 5000
Else
WScript.Sleep 3000
End If
Loop
If the window I need closed is active and then the following script is ran the window will close. It's almost like I need to piece the top and bottom code here together to achieve what I need, but I'm not sure how.
Dim oShell
Set oShell = CreateObject("WScript.Shell")
If oShell.AppActivate("Untitled - Notepad") Then
WScript.Sleep 500
oShell.SendKeys "%{F4}"
End If
I'm trying to find a script that will run on startup and wait for a window with a specific title to open and then close it once it is detected. It would be even better if I could control how long the window remains open once detected, but if I could just get it to close that would suffice.
I think I've found a good solution. I found this post and modified the answer. Does anyone see any issues with this?
' Will loop forever checking for the message every half a second
' When it finds the message it will close the window
Set wshShell = CreateObject("WScript.Shell")
Do
ret = wshShell.AppActivate("Untitled - Notepad")
If ret = True Then
wshShell.SendKeys "%{F4}" 'ALT F4
End If
WScript.Sleep 500
Loop
Set wshShell = CreateObject("WScript.Shell")
Do
ret = wshShell.AppActivate("Untitled - Notepad")
If ret = True Then
wshShell.SendKeys "%{F4}" 'ALT F4
End If
WScript.Sleep 500
Loop
The only trouble i see is the Alt+F4 will sequentially close windows until it will want to shut down windows itself. kinda makes me nervous even though this script will only detect the name you give it.
I tried the script and it works fine but what about using the escape key for certain windows?
The other thing i do not like is this is always running and taking resources. I slowed down the loop so it will at least be paused in the background most of the time..

vbscript - how to send keystrokes to internet explorer

I've read every question that came up when I typed my title, as well as several other web pages, and I still haven't found the answer I'm looking for. I believe this is fairly straightforward, just must be missing something as my program doesn't do anything.
Here's what I want it to do (for all practical purposes, let's say I'm searching for my favorite discussion here on SO):
Have the main SO page loaded (stackoverflow.com/).
Utilize the Open File (CTRL+O) feature of IE to enter the specific address of the page I'm looking for.
Utilize the Select All (CTRL+A) feature to highlight the entire text to be copied.
Utilize CTRL+C and CTRL+V to, respectively, copy and paste this into a word document for presentation purposes.
Here's the code I have so far:
' Sets up the objects.
Dim objIE, WshShell, objWord
Set wshShell = WScript.CreateObject ("WSCript.shell")
Set objIE = CreateObject("InternetExplorer.Application")
Set objWord = Application.CreateObject("Word.Application")
Dim i, strUserID
with CreateObject("InternetExplorer.Application")
wshShell.SendKeys "^O"
.navigate "http://stackoverflow.com/questions/[link of question would go here]"
wshShell.SendKeys "^A"
wshShell.SendKeys "^C"
AppActivate ("Document1 - Microsoft Word")
wshShell.SendKeys "^V"
end with
For some reason, this isn't working the way I want it to. Any suggestions?

Focus moves next tab if user press any key

I tried making a script that should perform the following functions:
runs in background
focus moves to next tab if user press any key
run on windows platform.
I used the following code but its not working :(
Please correct me if I had made a error in code.
Set wshShell = WScript.CreateObject("WScript.Shell")
Dim a
Do
a = WScript.StdIn.Read(1)
wshShell.SendKeys "{TAB}"
Loop

Resources