vbScript AppActivate activates random apps - google-chrome

I am trying to write a vb-script to do the following
Launch Chrome
Navigate to a specified website
Loop and keep refreshing that specific tab
I am able to get #1 and #2 to work, using the following code. The refresh works as well. The only issue is that the refresh happens to the windows which are active. The AppActivate part - which is supposed to shift focus to a given window is not working. Code here.
Dim iURL
Dim objShell
iURL = "SampleURL"
set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "chrome.exe", iURL, "", "", 1
Do While True
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.AppActivate "Remote Access Asia - Google Chrome"
WSHShell.SendKeys "{F5}"
WScript.Sleep 30000 ' 30 seconds
Loop
The window title I am using was determined by using the tasklist command (tasklist /v /FO:CSV). I have tried using various versions (substrings) of the title shown. I have used chrome.exe as well, but nothing helps. The refresh is not limited to tabs of Chrome - it happens with other apps e.g. notepad as well.
Any thoughts would be much appreciated.

Your code worked fine for a Chrome window I already had open. The issue may be with ShellExecute. I had success using Run and ensuring the site opened in its own window using the --new-window parameter. It's also unnecessary to have the CreateObject inside the While loop. Try it like this:
Set oWSH = CreateObject("WScript.Shell")
URL = "SampleURL"
oWSH.Run "chrome.exe --new-window " & URL
Do While True
oWSH.AppActivate "Remote Access Asia - Google Chrome"
oWSH.SendKeys "{F5}"
WScript.Sleep 30000 '30 seconds
Loop

Related

Opening Chrome browser on a variable page using vbscript

This is my code for opening Chrome browser on a variable page using vbscript:
Set browobj = CreateObject("Wscript.Shell")
siteA = "http://...../"
browobj.Run "chrome -url " & siteA
WScript.Sleep OneSecond*60
siteB = "http://..../Gest.do?operation=export&eser=123&ver=456"
browobj.Run "chrome -url " & siteB
Set browobj = Nothing
The first step opens the web page ( siteA ) for user authentication:
siteA = "http://...../"
browobj.Run "chrome -url " & siteA
The second step opens a link ( siteB ) where you pass variables for downloading an excel file :
WScript.Sleep OneSecond*60
siteB = "http://..../Gest.do?operation=export&eser=123&ver=456"
browobj.Run "chrome -url " & siteB
The second link ( siteB ) with the variables is opened in a new Chrome tab and the download is stopped.
Instead if the second link ( siteB ) opens in the same tab of the siteA the download is started. Tried manually.
I need reuse the same tab on is opening the siteA.
How to do opening the second link ( siteB ) opens in the same tab of the siteA ?
Please can you help me ?
Edit #01
browobj.Run start & siteB
Since chrome is available as a command:
chrome /new-tab somesite.com
However if chrome isnt available as a command but IS the default browser you can use:
start "" "https://somesite.com"
This should make it open in a new tab on the active window.
If you can't guarantee Chrome is the default browser. You can find the path to the chrome.exe and use something like:
"<Path of chrome here>" /new-tab "https://somesite.com"

VBA to VBS - iframe permission denied

I recently wrote an Excel VBA script to login and navigate an intranet site to download a CSV report. It contains some links and buttons that I need to click inside an iframe. It took some effort to figure out the iframe stuff, but it works. I still don't know how to click "Save" without the download file dialog box being the active window, but that's for another day.
I'm in the process of converting this script to VBS and have run into this error message:
Here are the relevant code snippets:
VBA Code (this works)
Set ie = New InternetExplorer
ie.Visible = True
...
Dim iframeDoc As MSHTML.HTMLDocument
Set iframeDoc = ie.document.frames("fmReports").document
' select the custom report
iframeDoc.getElementById("tvCustomReport").Click
Application.Wait (Now + TimeValue("00:00:03"))
' run the report
iframeDoc.getElementById("btnRunReport").Click
VBS Code (this presents the error dialog above)
Dim oIE
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Visible = True
...
Dim iframeDoc
Set iframeDoc = oIE.document.getElementById("fmReports").ContentWindow.Document
' select the custom report
iframeDoc.getElementById("tvCustomReport").Click
WScript.Sleep 3000 'wait here just in case
' run the report
iframeDoc.getElementById("btnRunReport").Click
Questions/Thoughts
I've turned off just about every security feature I can find in IE.
Are these different domains? (XSS issue perhaps)
The main intranet site url is http://192.168.0.111/app2019 while the contents of the iframe url is http://192.168.0.111/app2018.
Line 49 (referenced in the screenshot) of my full script is the second line in the VBS snippet (Set iframeDoc =...)
Am I missing something obvious?

How to open an appication using VBScript within an HTA file

I am having trouble with getting the HTML Application (MeowcatSoftware Launcher Demo.HTA on GitHub) to open a target application, for example, MultiToolv0.2.exe. Is there a way to open the target applications such as the MultiTool using VBScript besides using Wscript.shell objects, which has been causing most of my problems?
I have tried the following, which didn't work:
Sub RunProgram
Set objShell = CreateObject(“Wscript.Shell”)
objShell.Run “notepad.exe c:\script\test.txt”
End Sub
(From 'Hey, Scripting Guy" Blog Post)
I played around a little with it but couldn't figure out how to achieve my goal. The blog post also mentioned using a Windows Shell object instead of Wscript.shell, but it looks like from the example that the Windows Shell object method was for opening a file using another program, and I just want it to simply open the target application. How do I open a program using VBScript within an HTA Application?
In vbscript this should work : You should using quote (") not like you posted in your question (“) and (”)
Call RunProgram()
Sub RunProgram
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "notepad.exe c:\script\test.txt"
End Sub

take a snapshot with a webcam from ms access form

i need to take a snapshot with webcam when someone press a button in access form.
Is it possible?
i know how open a program from access but i'm stuck on how to trigger the event
the code
Private Sub Command1_Click()
Dim stAppName As String
stAppName = "C:\Program Files\myapp"
Call Shell(stAppName, 1)
End Sub
now let's say the snapshot trigger by f12 key in the app
how do i get the f12 key to click automatically
ok i got it
if any one want to know here is the method
1.by 2 macros "runapplication" & "sendkeys"
with "runapplication" just put the path of the app
with "sendkeys" just put the command SendKeys "{yorkey}"
by the way you need to press show all command in the the toolbar
or you can do it in vba code
You could try this if you are in windows 8/8.1
Dim cameraPath As String
cameraPath = "shell:AppsFolder\Microsoft.MoCamera_cw5n1h2txyewy!Microsoft.Camera"
Shell "explorer " & cameraPath

Setting Task Manager to Run VB Script

I have having task manager call up a VB Script which opens an access document at a certain time everyday, and when this document opens it has VBA Code set up to export the file as a different file type. I am getting an error back that will not allow this to run in task manager. I am really confused, because this should be a really easy task it really is creating a new access program opening the document, and then quitting access. I know that the VBA Code in the access file is correct, because it works OK when the file is opened. Task manager is simple so I know it has to be something with my VB script being incorrect(formatting maybe?), because I double click it to run an I get an run error. I would just set task manager to open the access file, but it will not quit access so we went this way. Below is the code in my script.
dim accessApp as variant
set accessApp = createObject("Access.Application")
accessApp.OpenCurrentDataBase("File Location")
accessApp.Quit
set accessApp = nothing
I did a few searches online already with little luck. Any help is greatly appreciated.
You cannot use a type in your Dim statements with VBScript:
dim accessApp
set accessApp = createObject("Access.Application")
accessApp.OpenCurrentDataBase("z:\docs\test.accdb")
''For testing purposes, comment out when testing is finished
msgbox accessapp.name
accessApp.Quit
set accessApp = nothing