Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
fEnumWindows()
End Sub
Public Const MAX_PATH As Short = 260
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Integer, ByVal lParam As Integer) As Integer
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Public Const WM_CLOSE As Short = &H10S
Public Function EnumFunc(ByVal hwnd As Integer, ByVal lpData As Integer) As Integer
Dim lResult As Integer
Dim sWndName As String
Dim szClassName As String
EnumFunc = 1
szClassName = Space(MAX_PATH)
sWndName = Space(MAX_PATH)
lResult = GetClassName(hwnd, szClassName, MAX_PATH)
szClassName = Microsoft.VisualBasic.Left(szClassName, lResult)
lResult = GetWindowText(hwnd, sWndName, MAX_PATH)
sWndName = Microsoft.VisualBasic.Left(sWndName, lResult)
'Dim vreturnvalue As Object
If InStr(sWndName, "Google - Windows") > 0 Then
'vreturnvalue = SendMessage(hwnd, WM_CLOSE, &O0S, &O0S)
MsgBox("Broswewr Session Identified")
'Now Need to navigate to specific URL..
End If
End Function
Public Delegate Function EnumFuncDeleg(ByVal hwnd As Integer, ByVal lpData As Integer) As Integer
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As EnumFuncDeleg, ByVal lParam As Integer) As Integer
Public Function fEnumWindows() As Boolean
Dim hwnd As Integer
Call EnumWindows(AddressOf EnumFunc, hwnd)
End Function
' Add a COM reference to 'Microsoft Internet Controls' to the project.
' Add a .NET reference to Microsoft.mshtml to the project.
' NOTE:
' Don't add an Imports mshtml if you want your Intellisense to work.
Imports System
Imports System.Collections.Generic
Imports SHDocVw
Public Class InternetExplorerWindows
Public Shared Function GetWindows() As Dictionary(Of String, String)
Dim list As New Dictionary(Of String, String)
For Each window As InternetExplorer In New ShellWindows()
' Skip Windows Explorer instances, since the Document type is IShellFolderViewDual2.
If TypeOf window.Document Is mshtml.HTMLDocument Then
list.Add(window.LocationURL, CType(window.Document, mshtml.HTMLDocument).body.innerHTML)
End If
Next window
Return list
End Function
Public Shared Function GetIFrameHTML(ByVal frameID As String) As Dictionary(Of String, String)
Dim list As New Dictionary(Of String, String)
For Each window As InternetExplorer In New ShellWindows()
' Skip Windows Explorer instances, since the Document type is IShellFolderViewDual2.
If TypeOf window.Document Is mshtml.HTMLDocument Then
Dim doc As mshtml.HTMLDocument = CType(window.Document, mshtml.HTMLDocument)
If doc.getElementById(frameID) IsNot Nothing Then
Dim frame As mshtml.HTMLIFrame = CType(doc.getElementById(frameID), mshtml.HTMLIFrame)
Dim window2 As mshtml.HTMLWindow2 = CType(frame.contentWindow, mshtml.HTMLWindow2)
Dim windowDocument As mshtml.IHTMLDocument2 = CType(window2.document, mshtml.IHTMLDocument2)
list.Add(window.LocationName, windowDocument.body.outerHTML)
End If
End If
Next window
Return list
End Function
End Class
Imports System
Imports System.Diagnostics
Imports System.Web
Imports System.Data
Imports System.Math
Imports System.Net
Imports System.Text
Imports System.IO
Imports Microsoft.Win32
Imports System.Runtime.InteropServices
Imports SHDocVw
Imports mshtml
Imports System.Threading
Imports MOZILLACONTROLLib
Public Class Form1
Dim test100 As String
Dim counter As Integer = 0
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
test100 = TextBox1.Text
GetWindows(test100)
End Sub
Public Const MAX_PATH As Short = 260
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Integer, ByVal lParam As Integer) As Integer
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Public Const WM_CLOSE As Short = &H10S
Public Const WM_LBUTTONUP As Integer = &H202
Public Const WM_LBUTTONDOWN As Integer = &H201
Public Const WM_RBUTTONDCLK As Integer = &H206
Public Const WM_SETTEXT As Integer = &HC
Public Function EnumFunc(ByVal hwnd As Integer, ByVal lpData As Integer) As Integer
Dim lResult As Integer
Dim sWndName As String
Dim szClassName As String
EnumFunc = 1
szClassName = Space(MAX_PATH)
sWndName = Space(MAX_PATH)
lResult = GetClassName(hwnd, szClassName, MAX_PATH)
szClassName = Microsoft.VisualBasic.Left(szClassName, lResult)
lResult = GetWindowText(hwnd, sWndName, MAX_PATH)
sWndName = Microsoft.VisualBasic.Left(sWndName, lResult)
'Dim vreturnvalue As Object
If InStr(sWndName, "Google - Windows") > 0 Then
AppActivate(sWndName)
End If
End Function
Public Delegate Function EnumFuncDeleg(ByVal hwnd As Integer, ByVal lpData As Integer) As Integer
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As EnumFuncDeleg, ByVal lParam As Integer) As Integer
Public Function fEnumWindows() As Boolean
Dim hwnd As Integer
Call EnumWindows(AddressOf EnumFunc, hwnd)
End Function
Public Shared Function GetWindows(test100 as String) As List(Of String)
Dim list As New List(Of String)
Dim test As String
Dim testF As String
Dim HandleIE As Integer
For Each window As InternetExplorer In New ShellWindows()
list.Add(window.LocationURL)
test = window.LocationURL
'MsgBox(window.LocationURL)
If test = "http://www.google.co.uk/" Then
MsgBox(window.LocationURL)
window.Navigate("www.play.com")
'Dim inp As Object
Thread.Sleep(10000)
HandleIE = window.HWND()
window.Document.All("searchstring").Value = test100
window.Document.All("go").Click()
End If
Next window
Return list
End Function
End Class
1) you can initiate the browser session and control that instance of the browser (easiest)
2) Find the hwnd of the current active browser (harder due to the user can have more than one browser instance open at one time).
Either way it is possible to then navigate fill form items and submit the form.