NEWS

[C#] Hướng dẫn lấy thông tin Your ID và Password của Ultraviewer Winform

[C#] Hướng dẫn lấy thông tin Your ID và Password của Ultraviewer Winform
Đăng bởi: Thảo Meo - Lượt xem: 6003 13:23:19, 16/03/2021DEVEXPRESS   In bài viết

Xin chào các bạn, bài viết trước mình đã hướng dẫn các bạn các lấy ID và Password của Teamviewer, hôm nay mình sẽ tiếp tục lấy ID và Password của Ultraviewer C#.

[C#] Get ID and Password Ultraviewer Winform

Ultraviewer là một phần mềm cho phép bạn điều khiển kết nối máy từ xa, và theo mình thấy thì ở Việt Nam Ultraviewer thường được sử dụng phổ biến không thua kém gì TeamViewer.

Với UltraViewer chúng ta sẽ dễ dàng tích hợp vào ứng dụng của mình để điều khiển từ xa Fixed lỗi cho khách hàng.

Bạn nào dùng phần mềm kế toán Misa thường thấy Ultraviewer được sử dụng rất nhiều ở đây.

Giao diện demo ứng dụng Ultraviewer c#:

ultraviewer_password_csharp

Source code C#:

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(string titleApp, string className)
        {
            TeamviewerHelper user = new TeamviewerHelper();
            IntPtr tvHwnd = WindowsApi.FindWindow(null, titleApp);
            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() == className)                          
                        {
                            var a = controlName;
                            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 == 100)
                            {
                                return user;
                            }
                        }
                        winSubPtr = WindowsApi.GetWindow(winSubPtr, GetWindowCmd.GW_HWNDNEXT);
                    }                 
                    winParentPtr = WindowsApi.GetWindow(winParentPtr, GetWindowCmd.GW_HWNDNEXT);
                }
            }
            return user;
        }       

    }
}

Và lấy data c#:

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)\TeamViewer\TeamViewer.exe");
            GetIDAndPassTeamViewer();
        }

        void GetIDAndPassTeamViewer()
        {
            var userInfo = TeamviewerHelper.GetUser("UltraViewer 6.2 - Free", "WindowsForms10.EDIT.app.0.141b42a_r28_ad1");

            txtYourID.Text = userInfo.Username;
            txtPassword.Text = userInfo.Password;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            GetIDAndPassTeamViewer();
        }
    }
}

Class WindowAPI.cs:

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
    }
}

Thanks for watching!

DOWNLOAD SOURCE

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

[C#] Hướng dẫn lấy thông tin Your ID và Password của Ultraviewer Winform
Đăng bởi: Thảo Meo - Lượt xem: 6003 13:23:19, 16/03/2021DEVEXPRESS   In bài viết

CÁC BÀI CÙNG CHỦ ĐỀ

Đọc tiếp
.