Answer the question
In order to leave comments, you need to log in
How to auto-enter the Login/Password pair in a third-party application?
Hello.
I have a program that requires a Login / Password pair to enter, but I need to authorize by Phone Number.
Roughly speaking, I need my program to enter the Login / Password into the forms of another program. I saw such functionality in password managers, how can I implement this?
Answer the question
In order to leave comments, you need to log in
In general, I solved the problem using AutoHotkey .
Not the safest solution, but there was no talk of security)
Our Exchange blunts, here is a clicker on the OK button in one of the Outlook windows.
Actually, everything is the same for you, only you will need to find two more textboxes in the desired window and send the corresponding WM_SETTEXT there before clicking:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace OutlookClicker
{
class Program
{
delegate bool EnumThreadDelegate(IntPtr hWnd, IntPtr lParam);
[DllImport("user32.dll")]
static extern bool EnumThreadWindows(int dwThreadId, EnumThreadDelegate lpfn, IntPtr lParam);
[DllImport("user32.dll")]
private static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr lParam);
private delegate bool EnumWindowProc(IntPtr hwnd, IntPtr lParam);
private static IEnumerable<IntPtr> EnumerateProcessWindowHandles(int processId)
{
var handles = new List<IntPtr>();
foreach (ProcessThread thread in Process.GetProcessById(processId).Threads)
EnumThreadWindows(thread.Id,
(hWnd, lParam) => { handles.Add(hWnd); return true; }, IntPtr.Zero);
return handles;
}
private static List<IntPtr> GetAllChildHandles(IntPtr hwnd)
{
List<IntPtr> childHandles = new List<IntPtr>();
GCHandle gcChildhandlesList = GCHandle.Alloc(childHandles);
IntPtr pointerChildHandlesList = GCHandle.ToIntPtr(gcChildhandlesList);
try
{
EnumWindowProc childProc = new EnumWindowProc(EnumWindow);
EnumChildWindows(hwnd, childProc, pointerChildHandlesList);
}
finally
{
gcChildhandlesList.Free();
}
return childHandles;
}
private static bool EnumWindow(IntPtr hWnd, IntPtr lParam)
{
GCHandle gcChildhandlesList = GCHandle.FromIntPtr(lParam);
if (gcChildhandlesList == null || gcChildhandlesList.Target == null)
{
return false;
}
List<IntPtr> childHandles = gcChildhandlesList.Target as List<IntPtr>;
childHandles.Add(hWnd);
return true;
}
private const uint WM_GETTEXT = 0x000D;
private const uint BM_CLICK = 0x00F5;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam,
StringBuilder lParam);
[STAThread]
static void Main(string[] args)
{
while (true)
{
foreach (var handle in EnumerateProcessWindowHandles(Process.GetProcessesByName("Outlook").First().Id))
{
StringBuilder message = new StringBuilder(1000);
SendMessage(handle, WM_GETTEXT, message.Capacity, message);
if (message.ToString() == "Windows Security")
{
var children = GetAllChildHandles(handle);
foreach (var child in children)
{
StringBuilder childtext = new StringBuilder(1000);
SendMessage(child, WM_GETTEXT, message.Capacity, childtext);
if (childtext.ToString() == "OK")
{
SendMessage(child, BM_CLICK, 0, null);
break;
}
} // enum children
break;
} // if our window
} // enum windows
} // while
} // Main
} // class Program
} // namespace
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question