Chrome: Possible to script like InternetExplorer.Application in VBScript? - google-chrome

I have a VBScript that uses InternetExplorer.Application to login to a website, then refresh the page every once in a while to keep the website from logging out due to inactivity. This sits on a dashboard screen mounted in our office. Is there a way to script Chrome in a similar way? It doesn't have to be VBScript, any language will do. We are looking to stop using Internet Explorer.

You can't control Google Chrome as an object in VBscript. Here's why: VBScript CreateObject Google Chrome
That being said, you CAN still manipulate a refresh on google chrome. Just copy the title of the page you want refreshing, and once the page has been activated, use a SendKeys command to cause it to refresh. e.g.(CTRL+R) - causes refresh, or in Sendkeys ("^r").
Once you've got it refreshing, just set it in a loop and set your wait period for however long you want.
'This is an infinite loop, only disposed of by exiting Wscript.exe or Cscript.exe
Do While(true)
Dim PageTitleToRefresh, IntervalinSeconds, x, objShell, Success
'Page Titles - NOT the page address - (google.com = NO) (Google = YES)
'Page Titles are normally stored at the top of the browser or in the tab name of the browser.
PageTitleToRefresh = "Google"
IntervalinSeconds = 10
x = IntervalinSeconds * 1000
Set objShell = WScript.CreateObject("WScript.Shell")
Do Until Success = True
Success = objShell.AppActivate(PageTitleToRefresh)
Wscript.Sleep 1000
Loop
wscript.echo "Activated, now refreshing"
objShell.SendKeys "^r"
Wscript.Sleep IntervalinSeconds
Loop

here is a way that I edited in js file, but can be also realized in vbs :
var fso = new ActiveXObject("Scripting.FileSystemObject");
var chrome = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
var url = 'http://google.com';
if (fso.FileExists(chrome)){
var objShell = WScript.CreateObject("Shell.Application");
objShell.ShellExecute(chrome, "--app="+url, "", "", 1);
}
else{ //if chrome doesn''t exists, so launch ie :
oIE1 = WScript.CreateObject ("InternetExplorer.Application");
oIE1.Visible = 1;
oIE1.AddressBar = 0;
oIE1.StatusBar = 0;
oIE1.ToolBar = 0;
oIE1.MenuBar = 0;
oIE1.Navigate(url);
}

Related

Enter incorrect password in Chrome, login dialog no longer popups

Set the application with webapi in IIS as window authentication
Using ajax to access this webapi
The system popups the login dialog
I enter domain account and wrong password
The strange thing is that the login dialog no longer popup, even I close and reopen it. Why chrome does not give me a chance to correct the wrong password? But IE could work.
I find the chrome contains a cookie with empty, without key and value when I debug it. If I delete it (by Chrome -- setting -- Privacy and security -- Clear browsing data), then it works again.
So, my question is how to delete this cookie by JS? or any other idea? It will be greatly appreciate.
You could set below browser setting to ask always login credential:
Open the Internet Explorer and click the settings icon, and then select the ‘Internet Options’.
Select the ‘Security’ tab in the pop-up window.
Choose the “Local intranet” and choose the “Custom level
Prompt Settings
Select “Prompt for user name and password” under “Logon” for the
Internet Explorer to prompt for getting the credentials from the user.
Select “Automatic logon with current user name and password” for the
Internet Explorer to automatically log on as the currently logged
user
Restart the Internet Explorer to apply the prompt settings.
for chrome:
Click the Chrome menu three dots in the toolbar and choose Settings.
Click Passwords.
Turn off "Auto Sign-in"
if you want to use js then you could try below code:
function deleteAllCookies() {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}
}
OR
function removeCookies() {
var res = document.cookie;
var multiple = res.split(";");
for(var i = 0; i < multiple.length; i++) {
var key = multiple[i].split("=");
document.cookie = key[0]+" =; expires = Thu, 01 Jan 1970 00:00:00 UTC";
}
}

search embeded webpage source in vb.net

I wrote a program that includes an embedded web browser that loads a website which have a changing part (the part changes about 2 times a week and it have no regular timing pattern) that I want to search for a particular part in the opened webpage source code after refreshing the webpage in a specified time interval.
I found many things similar to my question but this is what I want and those questions doesn't have:
search embedded webpage source (they searching the webpage without embedding, and I had to embed it because I had to login before I see the particular page)
so this is the procedure I'm trying to do:
1- open a website in embedded web browser
2- after user logged in, with a press of button in program, it hides the embedded
web browser and start to refresh the page in a time interval (like
every minute) and search if the particular code changed in the source of
that opened webpage
any other/better Ideas appreciated
thanks
Many years ago I wrote an app to reintegrate forum posts from several pages into one and I struggled with the login issue too and thought it was only possible using an embedded browser. As it turns out, it's possible to use System.Net in .NET to handle web pages that need a login as you can pull the cookies out and keep them on hand. I would suggest you do that and move away from the embedded browser.
Unfortunately I wrote the code in C# originally, but as it's .NET and is mostly classes-based, it shouldn't be too difficult to port over.
The Basic Principle
Find out what information is included in the POST when you login, which you can do in Chrome with developer mode on (F12). Convert that to a byteArray, POST it to the page, store the cookies and make another call with the cookie data later on. You will need a class variable to hold the cookies.
Code:
private void Login()
{
byte[] byteArray = Encoding.UTF8.GetBytes("username=" + username + "&password=" + password + "&autologin=on&login=Log+in"); // Found by investigation
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("yourURL");
request.AllowAutoRedirect = false;
request.CookieContainer = new CookieContainer();
request.Method = "POST";
request.ContentLength = byteArray.Length;
request.ContentType = "application/x-www-form-urlencoded";
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
if (((HttpWebResponse)response).StatusCode == HttpStatusCode.Found)
{
// Well done, your login has been accepted
loginDone = true;
cookies = request.CookieContainer;
}
else
{
// If at first you don't succeed...
}
response.Close();
}
private string GetResponseHTML(string url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = false;
// Add cookies from Login()
request.CookieContainer = cookies;
request.ContentType = "application/x-www-form-urlencoded";
WebResponse response = request.GetResponse();
string sResponse = "";
StreamReader reader = null;
if (((HttpWebResponse)response).StatusCode == HttpStatusCode.OK)
{
reader = new StreamReader(response.GetResponseStream());
sResponse = reader.ReadToEnd();
reader.Close();
}
response.Close();
return sResponse;
}
Hope that helps.
I had to change to C# and I found what I was looking for:
string webPageSource = webBrowser1.DocumentText;
That gave me the source of web page opened in webBrowser1 control.

Extension/File type of uploaded Word Document

I am trying to upload a Word Document to my personal box account using Box Windows SDK V2 using the following code.
using (Stream s = new FileStream("C:\\word.docx",
FileMode.Open, FileAccess.Read,
FileShare.ReadWrite))
{
MemoryStream memStream = new MemoryStream();
memStream.SetLength(s.Length);
s.Read(memStream.GetBuffer(), 0, (int)s.Length);
BoxFileRequest request = new BoxFileRequest()
{
Parent = new BoxRequestEntity() { Id = "0" },
Name = TxtSaveAS.Text
};
BoxFile f = await Client.FilesManager.UploadAsync(request, memStream)
The document gets uploaded successfully in root folder but the problem is, the extension of document is set to "File" (which is not previewed by Box because of having unsupported extension, neither it gets the icon of word document) rather than "docx" though it still gets open correctly in Microsoft word.
How to upload file using box windows sdk with respective extensions.
suggestions are greatly welcomed.
In order to upload the file with the correct extension, simply append the extension to the Name.
BoxFileRequest request = new BoxFileRequest()
{
Parent = new BoxRequestEntity() { Id = "0" },
Name = TxtSaveAS.Text + ".docx"
};

How to Accessing .vbs file in Firefox and Chrome Browser Using Html

Am Calling Notepad.vbs File In IE Browser... It Works
The Notepad.vbs Contains
Dim obj
Set obj = WScript.CreateObject( "WScript.Shell" )
obj.Exec("notepad.exe")
Set obj = Nothing
How To Executing This Notepad.vbs In FireFox and Chrome Browser....?
CreateObject is ActiveX technology. It's supperted only in Internet Explorer.
Whatever browser we can run the vbs script file using ASP (Server Side Script)
(I.E.,):
<%
Dim obj
Set obj = WScript.CreateObject( "WScript.Shell" )
obj.Exec("notepad.exe")
Set obj = Nothing
%>

How to access downloaded sound in IsolatedStorage via URI (WP8)?

I am struggling with this problem of accessing the sound file (mp3) download in isolated storage to be used in Alarm ,
The problem mentioned before
I am getting this error:
BNS Error: The action request's sound uri is invalid
Please help me but remember I am using the sound file for Alarm
Regarding the code it is the same as the link above.
This is download and save code of the sound file :
Public Async Function DownloadFile(url As Uri) As Task(Of Stream)
wc = New WebClient()
AddHandler wc.OpenReadCompleted, AddressOf OpenReadCompleted
AddHandler wc.DownloadProgressChanged, AddressOf DownloadProgress
wc.OpenReadAsync(url)
Dim r As IO.Stream = Await tcs.Task
Return r
End Function
Private Sub OpenReadCompleted(sender As Object, e As OpenReadCompletedEventArgs)
If e.[Error] IsNot Nothing Then
tcs.TrySetException(e.[Error])
ElseIf e.Cancelled Then
tcs.TrySetCanceled()
Else
tcs.TrySetResult(e.Result)
Dim file As IsolatedStorageFile
file = IsolatedStorageFile.GetUserStoreForApplication()
Using Stream As IsolatedStorageFileStream = New IsolatedStorageFileStream("Sound.mp3", System.IO.FileMode.Create, file)
Dim buffer As Byte() = New Byte(1023) {}
While (e.Result.Read(buffer, 0, buffer.Length) > 0)
Stream.Write(buffer, 0, buffer.Length)
End While
End Using
End If
End Sub
Private Sub DownloadProgress(sender As Object, e As DownloadProgressChangedEventArgs)
Proind.Value = e.ProgressPercentage / 100
Proind.Text = e.ProgressPercentage.ToString & " %" & " ( " & (e.BytesReceived \ 1000).ToString & "/" & (e.TotalBytesToReceive \ 1000).ToString & " ) KB"
End Sub
The problem is that you are trying to set a file in the isolated storage as the sound of the alarm, and that's not allowed. Only files packaged in .xap can be set as sound source of the alarm:
Remarks
The Sound URI must point to a file packaged in the application’s .xap
file. Isolated storage is not supported. When the alarm is launched,
the sound is played quietly and then gradually increases in volume.
There is no way to modify this behavior.
From:
Alarm.Sound Property
However, there is a way you could use a downloaded song as alam's sound. In OpenReadCompleted method, instead of saving the downloaded file in the isolated storage, create a file using File.Create method, and store the data there. Then it will be possible to use this file as the alarm sound:
Here is the C# code, I think you will easily translate to VB:
byte[] buffer = new byte[e.Result.Length];
e.Result.Read(buffer, 0, buffer.Length);
using (var fs = File.Create("file.mp3"))
{
fs.Write(buffer, 0, buffer.Length);
}
Then, you can set the Sound property of the alarm as:
alarm.Sound = new Uri("/file.mp3", UriKind.Relative);