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ọ.
- Mở ứng dụng ultraviewer, nếu ứng dụng cho chưa khởi động.
- Chờ ứng dụng đến khi nào hoàn thành get đầy đủ ID và PASSWORD.
- Copy thông tin vào clipboard.
Đầ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; } } }
Chúc các bạn thành công với thủ thuật trên.
No comments:
Post a Comment