Hillis1988
New member
- Joined
- Mar 20, 2015
- Messages
- 4
- Programming Experience
- 3-5
Hi ladies and gents,
I have been making something which harvests data from a sybase system which is linked through MS Access. It is a terrible system in the making, but unfortunately i do not have any better way to do it in the environment I have, as the access DB is needed by a whole bunch of other dependencies made by others.
I have a console app built using vb2010 and .NET 4.0 that needs to put a password into a sybase popup box which asks for credentials, I need to do this because this same box prevents all of my automation running whilst it waits on a password. Although I havn't built it yet here is my intention.
Here is the code I have, which is simply trying to send the text to the text box. I know I have the correct Window Handles as I have used WinSpy , and I know they are editable boxes programmatically, because WinSpy can edit them from within itself.
I figured there is no point writing the rest of the code until I get this bit working, so if anyone who can tell me what is wrong with this it would be greatly appreciated.
PS: The code is not smoothed out as I am experimenting, so please forgive
Module Module1
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWndParent As IntPtr, ByVal hWndChildAfter As Integer, ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As Long, ByVal wParam As IntPtr, ByVal lParam As String) As Long
Private Enum WindowMessages
WM_SETTEXT = &HC
End Enum
Sub Main()
Dim hWnd As IntPtr = FindWindow(vbNullString, "Logon to Sybase")
Console.WriteLine(hWnd) 'confirmed correct with WinSpy++
Dim hWndStatic As IntPtr = FindWindowEx(hWnd, IntPtr.Zero, "edit", "")
Console.WriteLine(hWndStatic) 'confirmed correct with WinSpy++
Dim hWndStatic2 As IntPtr = FindWindowEx(hWnd, hWndStatic, "Edit", "")
Console.WriteLine(hWndStatic2) 'confirmed correct with WinSpy++
Dim hWndStatic3 As IntPtr = FindWindowEx(hWnd, hWndStatic2, "Edit", "")
Console.WriteLine(hWndStatic3) 'confirmed correct with WinSpy++
Dim editTxt As String
editTxt = "Password"
Threading.Thread.Sleep(1000) 'it sometimes hasnt drawn the window so it returns nothing
SendMessage(hWndStatic3, WindowMessages.WM_SETTEXT, 0, editTxt)
Console.ReadLine()
End Sub
End Module
I have been making something which harvests data from a sybase system which is linked through MS Access. It is a terrible system in the making, but unfortunately i do not have any better way to do it in the environment I have, as the access DB is needed by a whole bunch of other dependencies made by others.
I have a console app built using vb2010 and .NET 4.0 that needs to put a password into a sybase popup box which asks for credentials, I need to do this because this same box prevents all of my automation running whilst it waits on a password. Although I havn't built it yet here is my intention.
- Open the thing that requires the logon to sybase,
- Wait until I find a window handle for a window with caption "Logon to Sybase"
- Dump the password in the box
- Press the ok button
- wait a second, then proceed.
Here is the code I have, which is simply trying to send the text to the text box. I know I have the correct Window Handles as I have used WinSpy , and I know they are editable boxes programmatically, because WinSpy can edit them from within itself.
I figured there is no point writing the rest of the code until I get this bit working, so if anyone who can tell me what is wrong with this it would be greatly appreciated.
PS: The code is not smoothed out as I am experimenting, so please forgive
Module Module1
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWndParent As IntPtr, ByVal hWndChildAfter As Integer, ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As Long, ByVal wParam As IntPtr, ByVal lParam As String) As Long
Private Enum WindowMessages
WM_SETTEXT = &HC
End Enum
Sub Main()
Dim hWnd As IntPtr = FindWindow(vbNullString, "Logon to Sybase")
Console.WriteLine(hWnd) 'confirmed correct with WinSpy++
Dim hWndStatic As IntPtr = FindWindowEx(hWnd, IntPtr.Zero, "edit", "")
Console.WriteLine(hWndStatic) 'confirmed correct with WinSpy++
Dim hWndStatic2 As IntPtr = FindWindowEx(hWnd, hWndStatic, "Edit", "")
Console.WriteLine(hWndStatic2) 'confirmed correct with WinSpy++
Dim hWndStatic3 As IntPtr = FindWindowEx(hWnd, hWndStatic2, "Edit", "")
Console.WriteLine(hWndStatic3) 'confirmed correct with WinSpy++
Dim editTxt As String
editTxt = "Password"
Threading.Thread.Sleep(1000) 'it sometimes hasnt drawn the window so it returns nothing
SendMessage(hWndStatic3, WindowMessages.WM_SETTEXT, 0, editTxt)
Console.ReadLine()
End Sub
End Module