NEWS

[C#] Hướng dẫn sử dụng thư viện AutoITx lấy id và password Ultraviewer trên winform

[C#] Hướng dẫn sử dụng thư viện AutoITx lấy id và password Ultraviewer trên winform
Đăng bởi: Thảo Meo - Lượt xem: 1064 16:03:41, 05/02/2024C#   In bài viết

Xin chào các bạn, bài viết hôm nay mình hướng dẫn các bạn các tự động lấy id và password trên ultraviewer sử dụng thư viện AutoIT trên C#, winform.

[C#] How to get id and password ultraviewer

Nếu là lập trình viên, chắc các bạn thường xuyên sử dụng Ultraviewer, khi gởi thông tin cho người khác nhờ fix lỗi hay support cho khách hàng.

Nếu các bạn, chụp màn hình mà gởi, hoặc thậm chí có nhiều bạn dùng điện thoại chụp gởi cho người mình nhờ cần support.

Thì người support cho bạn, có cảm giác rất khó chịu. Và nhiều khi không muốn fix lỗi cho bạn nữa.

Nên khi bạn muốn nhờ ai đó, remote để sửa fix bug cho mình thì phải copy id và mật khẩu cụ thể gởi họ.

Trong bài viết này mình sẽ dùng thư viện AutoItX C# thực hiện công việc sau:

  1. Mở ứng dụng ultraviewer, nếu ứng dụng cho chưa khởi động.
  2. Chờ ứng dụng đến khi nào hoàn thành get đầy đủ id và password.
  3. Copy thông tin vào clipboard.

Và bây giờ các bạn có thể dễ dàng dùng Ctrl +V hoặc paste để gởi thông tin remote cho người cần remote qua zalo, telegram...

auto_it_info

Đầu tiền, các bạn cài đặt thư viện AutoIt từ nuget:

NuGet\Install-Package AutoItX.Dotnet -Version 3.3.14.5

Full source code C#:

using AutoIt;
using System;
using System.Drawing;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using System.Windows.Forms;

namespace TestAutoIT
{
    public partial class Form1 : Form
    {
        public string pathAppUltraviewer = "C:\\Program Files (x86)\\UltraViewer\\UltraViewer_Desktop.exe";      
        public string titleApp = "UltraViewer 6.6 - Free";
        public Form1()
        {
            InitializeComponent();
            this.Size = new Size(1, 1);
            this.StartPosition = FormStartPosition.Manual;

        
            this.Location = new Point(-1000, -1000); 

            // Show the form
            this.Show();
        }

        protected override async void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            AutoItX.Run(pathAppUltraviewer, "", AutoItX.SW_SHOW);
            AutoItX.WinWait(titleApp, "");
            var credentials = await GetCredentialsAsync();
            Clipboard.SetText($"{credentials.Item1}\n{credentials.Item2}");

            var infoUltraviewer = $"{credentials.Item1}\n{credentials.Item2}";
            string localAppDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

           
            string zaloPath = Path.Combine(localAppDataFolder, "Programs", "Zalo", "Zalo.exe");

            ////Toast.Build(this, infoUltraviewer).Show();
            AutoItX.Run(zaloPath, "", AutoItX.SW_SHOW);

            //AutoItX.WinWaitActive("Zalo");

            //IntPtr windowHandle = AutoItX.WinGetHandle("[CLASS:Chrome_WidgetWin_1];[TITLE:Zalo]");

            //if (windowHandle != IntPtr.Zero)
            //{


            //    var windowInfo = AutoItX.WinGetPos(windowHandle);
            //    int centerX = windowInfo.X + windowInfo.Width / 2;
            //    int centerY = windowInfo.Y + windowInfo.Height / 2;
            //    AutoItX.MouseClick("left", centerX, centerY);


            //}
            //else
            //{
            //    Console.WriteLine("Failed to get window handle.");

            //}
            //SendTextWithDelay($"Thông tin Ultraviewer: ", 10);
            //AutoItX.Send("{ENTER}");

            //SendTextWithDelay($"{credentials.Item1}", 100);
            //AutoItX.Send("{ENTER}");
            //SendTextWithDelay($"{credentials.Item2}", 100);
            //AutoItX.Send("{ENTER}");

            Application.Exit();
        }

        public void SendTextWithDelay(string text, int delayBetweenCharacters)
        {
            foreach (char c in text)
            {
                AutoItX.Send(c.ToString());
                System.Threading.Thread.Sleep(delayBetweenCharacters);
            }
        }


        private Task<(string, string)> GetCredentialsAsync()
        {
            var tcs = new TaskCompletionSource<(string, string)>();

            ThreadPool.QueueUserWorkItem(state =>
            {
                string username = "";
                string password = "";

                do
                {
                    username = AutoItX.ControlGetText(titleApp, "", "[CLASS:WindowsForms10.EDIT.app.0.34f5582_r15_ad1; INSTANCE:3]");
                    Thread.Sleep(100); 
                } while (username == string.Empty);

                password = AutoItX.ControlGetText(titleApp, "", "[CLASS:WindowsForms10.EDIT.app.0.34f5582_r15_ad1; INSTANCE:4]");

                tcs.SetResult((username, password));
            });

            return tcs.Task;
        }
    }
}

 

Thanks for watching!

DOWNLOAD SOURCE

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

[C#] Hướng dẫn sử dụng thư viện AutoITx lấy id và password Ultraviewer trên winform
Đăng bởi: Thảo Meo - Lượt xem: 1064 16:03:41, 05/02/2024C#   In bài viết

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

Đọc tiếp
.