How to automate a windows form application without windows scheduler? - c#

I need to make an application which automatically moves files from source folder to destination folder on specified "time"(2 different times in a day). Once entered, this app should run daily. I have made a form application which moves file perfectly on button click. I need to implement this without any button click interaction.
Scheduling using Windows Task Scheduler is not an option for me.

One way I have achieved exactly that by creating a windows service project and put all the button click logic in a class library.
For scheduling the service i used Quartz.Net so that it can triggers the job/service at given interval.
You can find more about Quarts.Net here.
Please do note that you need administrative access to install and run your windows service.

Related

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.

C# WinForms: Creating a background notification application

For practical purposes but also as a learning exercise, I am wanting to create notification application to remind me of friend's Birthdays. I would like the application to be running in the background so that it can check the current date against user configured reminders. If a reminder is due then the user is displayed a simple Window that will allow them to snooze or dismiss the notification. I want the application to have user specific notifications (i.e. User A's notifications are not seen when User B is logged in).
Option 1 - Application launched upon Windows startup:
I thought about keeping it simple by checking when to display notifications only when the application starts up. I would then put a shortcut in the Windows Startup folder. However, this probably wouldn't work if the PC is put to sleep and resumed each day.
Option 2 - Application constantly running in background:
I then thought about making the application so it minimises to an icon in the System Tray and thus would constantly be running in the background. It would then periodically check when to display notifications.
Option 3 - Using Windows Service with application:
I then thought about using a Windows Service to do the periodic checks as to when to display notifications. Obviously, a Windows Service cannot display UI notifications so it would need to use some other mechanism for notification (e.g. sending an email). An application could then be used to configure settings that the service uses.
Are there any other options that I have not considered which would work better. I'm currently inclined to go with option 2 for my first implementation but could look to move to a better solution afterwards.
TIA
Your option 2 is the optimal one since you are aimed to distinct users and their reminders - your application runs in the context of a particular user, you already know which remainders need to be shown. Of course, you could go for the third option but this way is really need more time to code and the code itself would be more complex. I would go for the second option. As your applications is WinForms, for the periodical checks I would recommend you to use System.Windows.Forms.Timer class.
By the way, showing an icon in the tray notification area does not make your application "run in the background", it is just a convenient way to show your application is up and running.

Creating VS 2010 executable for Daily Tasks

I want to create an executable in VS 2010. This executable will be create an excel spreadsheet and will transfer that file via FTP. I want this executable to be fired off via Windows tasks.
What is the best way to accomplish this? Would I create a regular windows form application, dll, or Empty Project, or windows service?
Thank you in advance for any assistance.
A plain old console application scheduled with the task scheduler should do the trick.
If you need the application to run when a computer is turned on but no one is logged in, create a service. If your application runs only when someone is logged in, but has no UI, use a console application. If your application runs only when someone is logged in and has a UI, use a Winforms app.
I'm not sure what the current best practice is, but in our shop we create console applications and use the task scheduler to execute them.
A library (dll) won't be executable from the task scheduler AFAIK, and a WinForms app isn't very useful for any app that runs automatically (i.e.: doesn't require user interaction).
A service would be appropriate for an application that needs to respond to system events/changes when they occur, which doesn't sound like your use case.

c# main project and service

Despite my thorough googling, I am still confused on this matter.
Let me explain my situation. I created a c# project which gives the user the ability to back up the database manually (via a button click). Now the user must be able to schedule a time at which the database back up will run automatically. To achieve this, I am planning on creating a service which is started via the windows scheduler when the set back up time is reached.
I will need the deploy the service along with the main project (In my head, the service will be a different project. Maybe I am wrong here.).
My question is how do I deploy the service when the user installs the main project?
PS: I am using c# express and sql 2008 R2 express.
What are you using to install the main application. Chances are you the said packaging tool will also have hooks for allowing you to install the service. For example, if you are using Wix to create a msi package to install the main application, then you can configure Wix to also install the service.
This google search will point you to relevant articles for the same.
If instead you are not using any installer tool, say you simply give the user a zip containing all executables, then you will need to manually install the service. This article is perfect to create a self installable service. You could use Process.Start to execute the installutil exe to acutally install/uninstall the service.
Edit1:
Building on Rup's comment to your question, you already have the code required to backup the database. All you need, is to be able to schedule this. Once the user enters a schedule in your UI, you can create the corresponding task in the Task Scheduler. Have that task execute your main application, passing in the argument -backup "dbName" or what ever info is needed for the before mentioned backup code to run.
You may use the following template [which is meant for a console app, but will work just fine for your gui app as well. All you will need to check is if any switches have been passed in, then do not start the gui, instead simple execute the backup function code.] ... There are also a lot of existing questions on StackOverflow on which commandline parsing tool to use ...
The approach I would take is create the project for the UI, create a project for the service. The service would be a windows service that would always be running and would be responsible for creating the scheduled task. (Rather than having a scheduled task start the service.) How you go about creating the scheduled task is fairly open, you could shell out AT, or you could do some COM interop with the TaskScheduler type libs. I hope this helps.

How to make an application automatically start at Windows start?

I am new to .NET, I have made a small app. I want that this app should start when we start Windows, also how to make this app be present like a system tray icon if we minimize it. The app is a Windows form application.
As far as having it start automatically you can make it a windows service or you can simply place it in the windows startup folder and it will automatically launch it. For the System tray you should look into the NotifyIcon control.
For starting: couple of options..
1: Use scheduled tasks - accessed through control panel / adminstrative tasks
2: Make a shortcut to your exe in the startup folder in your start menu
For system tray: refer to this question: What's the proper way to minimize to tray a C# WinForms app?
in addition to what #Jesus said
you can also add a registry entry for start up. Windows service wouldn't do if your app is requiring the tray icon.
Best bet IMO is to make an installer project and configure the installer to have it start with windows when it's installed. Let the installer figure it out.

Categories