Esempio n. 1
0
        private static IntPtr FindWindow(string caption, int waitSec)
        {
            int counter = 0;

            waitSec *= 20;
            IntPtr hWnd = IntPtr.Zero;

            while (counter <= waitSec && hWnd == IntPtr.Zero)
            {
                hWnd = NativeCode.FindWindow(null, caption);
                counter++;
                System.Threading.Thread.Sleep(50);
            }

            return(hWnd);
        }
Esempio n. 2
0
        private static void SendRadminCredentials(string caption, NetworkCredential credential, int waitSec)
        {
            IntPtr mainWindowHandler = FindWindow(caption, waitSec);

            if (mainWindowHandler != IntPtr.Zero)
            {
                IntPtr radminEditBox1 = NativeCode.FindWindowEx(mainWindowHandler, IntPtr.Zero, "Edit", null);
                NativeCode.SendMessage(radminEditBox1, NativeCode.WM_SETTEXT, 0, credential.UserName);
                IntPtr radminEditBox2 = NativeCode.FindWindowEx(mainWindowHandler, radminEditBox1, "Edit", null);
                NativeCode.SendMessage(radminEditBox2, NativeCode.WM_SETTEXT, 0, credential.Password);
                IntPtr radminButton1 = NativeCode.FindWindowEx(mainWindowHandler, radminEditBox2, "Button", null);
                IntPtr radminButton2 = NativeCode.FindWindowEx(mainWindowHandler, radminButton1, "Button", null);
                NativeCode.SendMessage(radminButton2, NativeCode.BM_CLICK, 0, null);
            }
            else
            {
                MessageBox.Show($"Cannot find the Radmin connection window.", Title);
            }
        }