Using C # code to simulate filling a text box and clicking a button

I am working on a C # program that automates tasks. For example, my program opens an external application (in particular, mstsc.exe) and uses the application. I want to write code that fills text fields with specific values ​​and presses certain buttons. What is the right and most elegant way to implement such operations in C # 4 code?

+6
source share
2 answers

my solution for this problem, it is resolved using "SendKeys":

var Proc = new System.Diagnostics.Process(); Proc.StartInfo.FileName = "C:\\Windows\\System32\\mstsc.exe"; //Proc.StartInfo.Arguments = "/v:" + "PCwg01"; normaly Proc.Start(); System.Threading.Thread.Sleep(100); SendKeys.Send("PCwg01"); //name or IP adress SendKeys.Send("\r"); 

Hope this helps;)

0
source

if your special target mstsc.exe uses its parameters :

 mstsc.exe [<Connection File>] [/v:<Server>[:<Port>]] [/admin] [/f] [/w:<Width> /h:<Height>] [/public] [/span] mstsc.exe /edit <Connection File> mstsc.exe /migrate 

else Windows input simulator (C # SendInput Wrapper - simulating keyboard and mouse) is a reliable and open source CodePlex library for your problem.

+2
source

Source: https://habr.com/ru/post/920658/


All Articles