Click here to Skip to main content
15,747,637 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I want to be able to emulate a user in my C# console app.

Example: process is a web browser opened by the app

Is there a way to have the C# find and recognize the various capabilities of the app and then work with these? For example, read data in the app's components or windows, press buttons, etc?

What I have tried:

Thanks to the help from various people in this forum, I was able to get to a point where I define a process and a process start point, so my C# console app at least now is aware of the external gui app. I just now need to process stuff in that app. Examples, war stories, anecdotes, beatings, etc would be appreciated. :)
Updated 21-Apr-23 2:25am
Richard Deeming 21-Apr-23 8:37am    
Perhaps you're looking for UI Automation?
UI Automation Fundamentals - .NET Framework | Microsoft Learn[^]

Microsoft also have "Power Automate", which includes a free tier that might do what you need.
Pada Temp 21-Apr-23 13:22pm    
This looks interesting. Thank you!

Already answered here in the comments by @OriginalGriff: Simulate sending a keystroke or keystrokes in C# console app?[^]

GUI apps don't use StandardInput - they accept messages from the OS that a key id down, up , or pressed instead. So a stream won't work, and Windows is not designed to make automating other GUI apps simple!

Instead, you need to use SendKeys / SendWait but even then, what you need to send will depend on the target app - you may need to send TAB characters to move between fields and so on.
Share this answer
Pada Temp 21-Apr-23 8:25am    
You are the man. Thank u!
To add to what Graeme has said ...
Is there a way to have the C# find and recognize the various capabilities of the app and then work with these? For example, read data in the app's components or windows, press buttons, etc?
And what good will that do you? You can't identify a control as a text box or a label just by looking at it's handle - which is about all you can get from a running app, so you certainly can't tell if you should send it the username or the password!

You need to look at the app and treat it the way a user would when he's used to it: "it starts in the username box, so type that, then TAB, then the password"

But ... if the app updates, it may start somewhere totally different, or the password could be on a different page.

What are you trying to automate anyway?
Share this answer
Pada Temp 21-Apr-23 8:35am    
I am trying to automate a weather data app so as to read data from it. I want to enter username and password, press OK button, then after log in read values such as day, temperature, and also be able to navigate the app programmatically. I want to be able to snag whatever it is the app is doing internally, such as reading values, etc. I realize that app updates is an issue, but if there is a way to get at the classes, buttons, variables, fields, etc that the app uses, that would be ideal.

I get the sense that this is asking too much out of the way Windows does forms and GUI apps....
OriginalGriff 21-Apr-23 8:45am    
No, that's not going to work - or at least not without huge amounts of work from you: apps just don't work that way. Do you even know what language the app is written in? Because that will have a major affect on how it's memory is organised - and that's assuming that you can get access to it's process memory which is by and large a big "no no" as far as the OS is concerned.

A much, much better idea is to see if the producers of the weather app have an API which allows you to access their data directly since it comes from the web.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900