Free Hit Counters

Sunday, January 23, 2011

TeamViewer ID and PASS

Imports System.Runtime.InteropServices
Imports System.Text

Module Module1

    <DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True)> _
    Private Function FindWindowByCaption(ByVal ZeroOnly As IntPtr, ByVal lpWindowName As String) As IntPtr
    End Function

    <DllImport("user32.dll", SetLastError:=True)> _
    Public Function FindWindowEx(ByVal parentHandle As IntPtr, ByVal childAfter As IntPtr, ByVal className As String, ByVal windowTitle As IntPtr) As IntPtr
    End Function

    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    Private Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInt32, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
    End Function

    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    Private Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInt32, ByVal wParam As Integer, ByVal lParam As StringBuilder) As IntPtr
    End Function

    Public Const WM_GETTEXTLENGTH As Integer = &HE
    Public Const WM_GETTEXT As Integer = &HD

    Sub Main()
        Dim view = "TeamViewer"
        Dim hWnd As IntPtr = FindWindowByCaption(IntPtr.Zero, view)
        Dim hWndID As IntPtr = FindWindowEx(hWnd, IntPtr.Zero, "Edit", IntPtr.Zero)
        Dim hWndPass As IntPtr = FindWindowEx(hWnd, hWndID, "Edit", IntPtr.Zero)
        Dim plID As IntPtr = SendMessage(hWndID, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero) + 1
        Dim plP As IntPtr = SendMessage(hWndPass, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero) + 1
        Dim sI As New StringBuilder(CInt(plID))
        Dim sP As New StringBuilder(CInt(plP))
        Dim pID As IntPtr = SendMessage(hWndID, WM_GETTEXT, CInt(plID), sI)
        Dim pPass As IntPtr = SendMessage(hWndPass, WM_GETTEXT, CInt(plP), sP)

        Form1.TextBox1.Text = "ID : " + sI.ToString
        Form1.TextBox2.Text = "Pass : " + sP.ToString
    End Sub

End Module

No comments:

Post a Comment

Free Hit Counters