- [C#] Di chuyển và thay đổi kích thước Control Winform khi ứng dụng đang chạy
- [VB.NET] Chia sẻ source tạo sắp xếp đội hình bóng đá Line-ups đội bóng
- [C#] Hướng dẫn chỉnh sửa Text của label trực tiếp trên winform
- [C#] Hướng dẫn custom TextBox giống Ultraviewer trên Winform
- [C#] Show Modal Winform like Bootstrap
- [DATABASE] Thứ tự thực hiện mệnh đề truy vấn SELECT trong Sqlserver
- [C#] Hướng dẫn viết addin Excel Lấy hình ảnh từ URL internet vào Excel
- [DATABASE] TSQL view max length all column data trên table Sqlserver
- [DEVEXPRESS] Hướng dẫn sử dụng MailMerge kèm Hình ảnh trên Winform
- [DATABASE] Hướng dẫn truy vấn xem kích thước lưu trữ của từng bảng ghi Table trên sqlserver
- [C#] Hướng dẫn Fake Date Time sử dụng thư viện Harmony
- [DATABASE] Phân biệt câu lệnh DDL và DML trong sqlserver
- [C#] Hướng dẫn convert file mã HTML sang file Pdf trên winform
- [DEVEXPRESS] Tạo các loại mã vạch Barcode trực tiếp trên Devexpress Barcode API
- [DEVEXPRESS] Hướng dẫn custom Simple button thành Progressbar
- [DATABASE] Tách số và chữ từ chuỗi - hàm tối ưu hóa tách số và chữ trong Sqlserver
- [C#] Tìm kiếm gần đúng Full Text Search sử dụng thư viện Lucene.NET
- [C#] Chia sẻ tài liệu, sdk và source code máy chấm công dòng máy ZKTeco
- [C#] Memory Cache là gì, và sử dụng trong ứng dụng Winform
- [DATABASE] Khóa chính Primary Key trong Sqlserver
[C#] Hướng dẫn lấy thông tin Your ID và Password của Teamviewer Winform
Lại là mình Thảo Meo đây các bạn, bài viết hôm nay mình sẽ hướng dẫn các bạn cách lấy Your ID và Password trên Teamviewer C# Winform.
[C#] Get Your ID And Password Teamviewer Winform
Vậy chúng ta cần lấy thông tin từ ứng dụng này nhằm mục đích gì?
Mình có một ví dụ như sau:
Mình phát triển một phần mềm và có tích hợp sẵn ứng dụng Teamviewer Portable kèm theo ứng dụng sản phẩm của mình.
Khi khách hàng báo lỗi ứng dụng, thì mình có thể dễ dàng gọi App lên mở Teamviewer và đọc thông tin Your ID và Password và gởi về cho mình.
Giúp mình dễ dàng Remote từ xa một cách nhanh chóng.
Dưới đây là giao diện Lấy YourID và Password Teamviewer c#, Winform:
Chi tiết ứng dụng các bạn xem video demo của mình:
Đầu tiên các bạn tạo cho mình WindowsApi.cs
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace GetIDAndPassTeamViewer
{
public class WindowsApi
{
[DllImport("User32.dll", EntryPoint = "FindWindow")]
public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, StringBuilder lParam);
[DllImport("user32.dll", EntryPoint = "GetWindowText")]
public static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int cch);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr GetWindow(IntPtr hWnd, GetWindowCmd uCmd);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
[DllImport("user32.dll", EntryPoint = "ShowWindow")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
}
public enum GetWindowCmd : uint
{
GW_HWNDFIRST = 0,
GW_HWNDLAST = 1,
GW_HWNDNEXT = 2,
GW_HWNDPREV = 3,
GW_OWNER = 4,
GW_CHILD = 5,
GW_ENABLEDPOPUP = 6
}
}
Tiếp theo, các bạn tạo thêm một class TeamviewerHelper.cs
:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace GetIDAndPassTeamViewer
{
class TeamviewerHelper
{
private static Regex userReg;
static TeamviewerHelper()
{
userReg = new Regex(@"d+ d+ d+", RegexOptions.Singleline | RegexOptions.Compiled);
}
public TeamviewerHelper()
{
Username = string.Empty;
Password = string.Empty;
Holder = string.Empty;
}
internal int _count;
public string Username;
public string Password;
public string Holder;
public static TeamviewerHelper GetUser()
{
TeamviewerHelper user = new TeamviewerHelper();
IntPtr tvHwnd = WindowsApi.FindWindow(null, "TeamViewer");
if (tvHwnd != IntPtr.Zero)
{
IntPtr winParentPtr = WindowsApi.GetWindow(tvHwnd, GetWindowCmd.GW_CHILD);
while (winParentPtr != IntPtr.Zero)
{
IntPtr winSubPtr = WindowsApi.GetWindow(winParentPtr, GetWindowCmd.GW_CHILD);
while (winSubPtr != IntPtr.Zero)
{
StringBuilder controlName = new StringBuilder(512);
WindowsApi.GetClassName(winSubPtr, controlName, controlName.Capacity);
if (controlName.ToString() == "Edit")
{
StringBuilder winMessage = new StringBuilder(512);
WindowsApi.SendMessage(winSubPtr, 0xD, (IntPtr)winMessage.Capacity, winMessage);
string message = winMessage.ToString();
if (userReg.IsMatch(message))
{
user.Username = message;
user._count += 1;
}
else if (user.Password != string.Empty)
{
user.Holder = message;
user._count += 1;
}
else
{
user.Password = message;
user._count += 1;
}
if (user._count == 3)
{
return user;
}
}
winSubPtr = WindowsApi.GetWindow(winSubPtr, GetWindowCmd.GW_HWNDNEXT);
}
winParentPtr = WindowsApi.GetWindow(winParentPtr, GetWindowCmd.GW_HWNDNEXT);
}
}
return user;
}
public static Dictionary<string, string> GetInfos(params string[] keys)
{
IntPtr tvHwnd = WindowsApi.FindWindow(null, "TeamViewer");
var sets = new HashSet<string>();
sets.UnionWith(keys);
return CheckPtrInfo(tvHwnd, sets);
}
public static Dictionary<string, string> CheckPtrInfo(IntPtr tvHwnd, HashSet<string> keys)
{
Dictionary<string, string> result = null;
if (tvHwnd != IntPtr.Zero)
{
tvHwnd = WindowsApi.GetWindow(tvHwnd, GetWindowCmd.GW_CHILD);
if (tvHwnd != IntPtr.Zero)
{
var message = GetMessage(tvHwnd);
if (keys.Contains(message))
{
tvHwnd = WindowsApi.GetWindow(tvHwnd, GetWindowCmd.GW_HWNDNEXT);
var text = GetMessage(tvHwnd);
if (result == null)
{
result = new Dictionary<string, string>();
}
result[message] = text;
}
while (tvHwnd != IntPtr.Zero)
{
var tempReuslt = CheckPtrInfo(tvHwnd, keys);
if (tempReuslt != null)
{
if (result == null)
{
result = tempReuslt;
}
else
{
foreach (var item in tempReuslt)
{
result[item.Key] = item.Value;
}
}
}
tvHwnd = WindowsApi.GetWindow(tvHwnd, GetWindowCmd.GW_HWNDNEXT);
}
}
}
return result;
}
public static string GetMessage(IntPtr tvHwnd)
{
StringBuilder winMessage = new StringBuilder(512);
WindowsApi.SendMessage(tvHwnd, 0xD, (IntPtr)winMessage.Capacity, winMessage);
return winMessage.ToString();
}
}
}
Và cuối cùng chúng ta gọi class TeamviewerHelper để sử dụng:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GetIDAndPassTeamViewer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnGet_Click(object sender, EventArgs e)
{
Process.Start(@"C:Program Files (x86)TeamViewerTeamViewer.exe");
GetIDAndPassTeamViewer();
}
void GetIDAndPassTeamViewer()
{
var dicInfo = TeamviewerHelper.GetInfos("Your ID", "Password");
if (dicInfo != null)
{
string yourID = "";
string password = "";
dicInfo.TryGetValue("Your ID", out yourID);
dicInfo.TryGetValue("Password", out password);
txtYourID.Text = yourID;
txtPassword.Text = password;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
GetIDAndPassTeamViewer();
}
}
}
Thanks for watching!