Reputation: 43
i am creating an application which opens a web browser( other than IE ) and navigates to a specific URL using VBScript and also identify the instance of the browser if it is already opened. The browser can be Safari, Chrome, Firefox or Opera. Till now i was able to open the browser and navigate to url using VBScript. Here's what i did -
Specific to IE
Dim ieObj As Object
Set ieObj = CreateObject("InternetExplorer.Application")
ieObj.Visible = True
ieObj.Navigate url
url is the address to which the browser should navigate to.
For other browser -
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run ("""C:\Program Files (x86)\Mozilla Firefox\firefox.exe""") & url
Set objShell = Nothing
here i can change the path for the application and it opens up fine.(i can change it more meaningful code so that's not an issue).
Now, i have the mechanism ready to detect IE browser instance-
Dim obj_Shell As Object
Dim obj_window_open As Object
Set obj_Shell = CreateObject("shell.application")
For Each obj_window_open In obj_Shell.Windows
//Logic to achieve functionality
//..End Each Loop
This piece of code works perfectly fine for IE and IE only.
Is there any way that we can do the same for other browsers like firefox and chrome? Help would be greatly appreciated since i have started learning VBScript a few days back.
Upvotes: 0
Views: 5250
Reputation: 6852
If you just want to open a website in the standard browser on the system, go with this:
set objwsh = CreateObject("WScript.Shell")
objwsh.Run "http://stackoverflow.com/"
On the other hand, here is a script that can search the running processes for specific names (or beginnings).
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& ".\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process")
For Each objProcess in colProcesses
for each targetItem in Array("Firefox", "Chrome") ' ...
if lcase(left(objProcess.Name, len(targetItem))) = _
lcase(targetItem) then
msgbox targetItem & " seems to be running (" & objProcess.Name & ")"
end if
next
Next
...based on http://msdn.microsoft.com/en-us/library/aa394599%28v=vs.85%29.aspx
But this won't really help you much, because e. g. Firefox does simply not provide a scripting interface.
Upvotes: 1