Opening Chrome browser on a variable page using vbscript - google-chrome

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"

Related

vbScript AppActivate activates random apps

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

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?

Saving a page and clicking on the save popup in chrome using AppleScript

I want to download a txt file, opened in a tab in chrome using AppleScript. I want the save as dialog of Mac to provide the default extension and the name of the file.
tell application "Google Chrome" to tell active tab of window 1 to save as "r1.txt"
I tried this approach, and some other approaches like
activate application "Google Chrome"
tell application "System Events"
tell process "chrome"
keystroke "s" using {command down}
delay 1
click button "Save" of sheet 1 of window 1
end tell
end tell
still am not able to click the save button in the modal.
This works for me using the latest version of Google Chrome and the latest version of MacOS Mojave
activate application "Google Chrome"
tell application "System Events"
repeat while not (exists of menu bar item "File" of menu bar 1 of application process "Chrome")
delay 0.1
end repeat
click menu bar item "File" of menu bar 1 of application process "Chrome"
repeat while not (exists of menu item 11 of menu 1 of menu bar item "File" of menu bar 1 of application process "Chrome")
delay 0.1
end repeat
click menu item 11 of menu 1 of menu bar item "File" of menu bar 1 of application process "Chrome"
repeat while not (exists of UI element "Save" of sheet 1 of window 1 of application process "Chrome")
delay 0.1
end repeat
click UI element "Save" of sheet 1 of window 1 of application process "Chrome"
end tell
My approach to this problem was to try and avoid scripting the UI if possible, which can be problematic and unreliable. Instead, I decided to use the shell command curl to do the downloading job for us instead of trying to manipulate Chrome into doing it.
All we need is the location of where to save the file to, which I've set as the location to which Google Chrome defaults to, namely ~/Downloads.
property path : "~/Downloads" -- Where to download the file to
use Chrome : application "Google Chrome"
property sys : application "System Events"
property window : a reference to window 1 of Chrome
property tab : a reference to active tab of my window
property URL : a reference to URL of my tab
property text item delimiters : {space, "/"}
on run
-- Stop the script if there's no URL to grab
if not (my URL exists) then return false
-- Path to where the file will be saved
set HFSPath to the path of sys's item (my path)
-- Dereferencing the URL
set www to my URL as text
-- Extract the filename portion of the URL
set filename to the last text item of www
-- The shell script to grab the contents of a URL
set sh to the contents of {¬
"cd", quoted form of the POSIX path of HFSPath, ";", ¬
"curl --remote-name", ¬
"--url", quoted form of www} as text
## 1. Download the file
try
using terms from scripting additions
do shell script sh
end using terms from
on error E
return E
end try
## 2. Reveal the downloaded file in Finder
tell application "Finder"
tell the file named filename in the ¬
folder named HFSPath to if ¬
it exists then reveal it
activate
end tell
end run
It's a longer script than your present one, but most of it is declarations of variables (and properties), after which the script does two simple things:
Grabs the URL of the active tab in Chrome, and downloads the contents of that URL into the specified folder, retaining the same filename and extension as the remote file;
Once the download is complete, it reveals the file in Finder.

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

Change Default Web Browser via Access vba

My default web browser is Google Chrome Version 39.0.2171.95 m. The following web address does not work properly in Chrome but does so in IE: "https://secure.crbonline.gov.uk/enquiry/multipleEnquirySearch.do". I have written the follwing code to try to open the link in IE but what it does is open IE and then open the hyperlink in Chrome. How can I get it to simply open in IE and not run Chrome in this instance?
Dim stAppName As String
stAppName = "C:\Program Files (x86)\Internet Explorer\iexplore.exe"
Call Shell(stAppName, 1)
FollowHyperlink "https://secure.crbonline.gov.uk/enquiry/multipleEnquirySearch.do"
Try including the URL along with stAppName.
Dim strApp As String
Dim strURL As String
strApp = "C:\Program Files (x86)\Internet Explorer\iexplore.exe"
strURL = "https://secure.crbonline.gov.uk/enquiry/multipleEnquirySearch.do"
Call Shell(strApp & " " & strURL, 1)