Automate a GUI Windows application with user inputs to run every week - c#

I have a simple Windows application which has two text boxes and one button called "Run". Currently, I have to manually enter the values in text boxes and click on Run button every week. I want to automate this process, so that no user interaction should be required. Can I write a script to do this?

I assume you have the source of your Windows application as you've tagged your question with C#. If so, then it's fairly straightforward to pass your text box values on the command line via something like Windows Task Scheduler, parse the command line parameters in your application, and pass them on to whatever you call when Run is pressed.

Kicking it off at every X interval is one thing. I would suggest the Windows Task Scheduler. However, it sounds like you need to interact with the GUI application after it's been launched. For that, all I can do is point you in the right direction. The only thing that comes to mind is to use a third-party GUI testing suite. Check out this list. You can script any of these suites to interact with the GUI, that is, input some data and click on the Run button.

Related

Need to make my tool work automatically without any button

I have one window's application in c# which generates mail by retrieving the data from the database on a button click and generate mails in outlook.
Now, I need to make my application to work automatically therefore, on every Monday it will start sending the mail by itself.
Please suggest me some idea and code which can resolve my issue.
Change the application to accept a command line argument to make it send the email when the application starts and shut down after. Then create a windows "scheduled task" to launch the app with the correct commandline argument.
Try to make Window Service and schedule it.
Basically you can put your code call on button click in a Console Program (output will be an .exe) and then schedule it with windows scheduler every Monday.
Hope it help you !

In Windows how to get highlighted text in a window that belongs to another process using C++ or C#?

It's in a C++ translation program. When user selects some text in some other program without pressing CTRL-C, I want to get the highlighted text so that I could translate it. C# solutions are welcome because this(text acquisition) is a relatively standalone component.
One possible solution is to add hook to mouse event. I detect the following messages: mouse drag with left button hold, then release left button. Then I send CTRL-C to the program and get the text from clipboard.
I save and restore clipboard so most programs would work well with the method. But I have observed some programs would process events like WM_KEYUP in their message loops. For these programs I send fake messages! Is there another safer way to get the highlighted text?
I was trying to find some API call to get text between two mouse cursor positions, but I cannot find one.
The right way to write a Windows program that interacts with another programs GUI interface is to use UI Automation. Specifically, you'll write a UI Automation Client.
It requires a bit of work, but a UI Automation solution will work with almost every other application. A hacky solution built on hooks and messages will also be a lot of work, but it will be very fragile. It will only work with certain kinds of applications in certain contexts. Lots of things can go wrong.

how to automate some actions on Windows form Application?

I have a working windows form desktop application that I have created. The application is doing some jobs on monthly basis. Every month I need to run the application and there is a connect button. which I click and then it loads up in a dropdown menu some lists and I choose one of them and click another button to do the job. So what I would like to do is automate this process and just let the application to do this job for me every month as a scheduled. I do not want to go inside to code and make it a console application and run the console application from tasks schedule. I am just wondering is there any way that I can create another small application and define the steps to take (similar Macros or test projects(codedUI Test)) to do the job for me?
May be you just need something like AutoHotkey? http://www.autohotkey.com/
It's already 'another small application' and you can 'define steps to take' with it :)
I recommend you Automa - Python tool/library for automating GUI applications. It's very easy to use and perfect for tasks you described:
click(Button("Connect"))
click(ComboBox("Drop Down Menu Name"), "Option 1")
press(ENTER)
You can save the commands in a text file with the .at extension and run it easily from command line whenever required:
> Automa.exe your_script.at
Disclaimer: I'm one of Automa's developers.

Is it possible to triger a keybord event in one application by function in another program?

Let's say that I've got a single program (let's say that it's GIMP).
I want to create an application which runs in the background. I want it to do nothing, but to "imitate" a user pressing the key f.e. once in 10 seconds, and I want the second program (f.e. GIMP) to react to this action as if it was really the user.
In other words, I guess that my program would just trigger some API-like function, which would trick the external application into assuming that the user hit f.e. Ctrl+S, and then the application would react by saving the current file.
Is it even possible in C#? I'm pretty sure that I came across this kind of code in C# a looong time ago.
I'm only asking for some direction, because so far I didn't come across anything like that in C#.
There is a API called SendKeys that should do the trick
http://www.codeproject.com/Articles/18366/Sending-Keystrokes-to-another-Application-in-C

Auto logon windows at a specific time using c#

Auto logon windows at a specific time. How can i do this in c# ?
Any ideas please...
Purpose : I need to perform some tasks at a specific time in midnight. which needs the windows to be logged on.
Take a look at the Scheduled Task. On the task panel you un-check the option "only after the current user logs on". That's it.
Update
So to make this with a little more explanation:
This was your question:
Purpose : I need to perform some tasks at a specific time in midnight. which needs the windows to be logged on
So to get this to work, you have to split your task a little bit up. At first write your task that should be performed (a batch-script, a self-written application, a third-party application with a configuration file or some command line parameters, etc.).
If you got your task up and you can run it on a single finger tip (e.g. click on a lnk file on your desktop, enter a single command on the command-line, etc.), it's time to automate your task for a specific time schedule. For this purpose Microsoft already provided a powerful tool, called Scheduled Tasks. It is located in the Control Panel. Here you can define Tasks which should be started with dozens of options and time plans. Just step through the wizard and after that make a double click or right click - Properties on the created task. Now step through all the TabPages and take a close look on all the available options. Everything you need can be solved here.
Update 2
So after reading your comment (and a few other):
If my system is locked, then i need it to get unlocked at a point of time
My first question would be: What do you mean with locked?
There are two states in which a system can be locked:
The system is freshly started, no session is running and you need to provide a username and a password to get a session to run.
A user has already logged in and the system is currently locked (cause the user pressed WinL, the screen saver is configured to lock, etc.).
The difference between those two states is, in the first you need to provide a username and a password, in the second one you only need to provide the password only.
What both have in common is you have to press CtrlAltDel to get the needed Dialog and this is not possible from an application.
If you really need to log-on or unlock the screen at a specific time you should start a search about gina.dll and how to replace or enhance it so that you can send a message to it, to do whatever you like. But this dll replacement can't be done in C#. It has do be done in C/C++. And i forgot, that the gina.dll approach only works on XP. For Vista/Win7 they changed the log-on process and the procedure to intercept it, but a search for the provided keywords should reveal the needed informations.
look at this thread.
You can replace your app with userinit.exe.
it runs before Explorer.

Categories