Windows system tray application not running from windows service and task schedular - c#

I have a windows service to create a process which will run a windows desktop GUI application, but service cannot run an application with UI.
I then moved to task schedular to run my windows UI application but unfortunately the exe starts in background and there is no UI in foreground. I can see a process running in task manager in both the case, task schedular and windows service.
Is there a way i want to run a windows desktop system tray application to run as soon as the machine starts.
Thanks!

you can try to put the application in the run registry for example.
if i am not mistaking the task scheduler is preventing interactive system tray items.
See this article for more info about this option

Related

Run out of process background task as administrator

I'm currently working on a UWP app that has an out-of-process background task (in a windows runtime component project). In the background task I'm trying to run a trace event session from the Microsoft.Diagnostics.Tracing.Session library, but it requires administrator privileges to run. Is there any way I can run the background task process as administrator?
hi maybe this answer will help you.
Hi,
No, auto-elevation for apps is not supported for Desktop Bridge apps.
This policy is called out in the preparation guide for the Desktop Bridge: https://learn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-prepare(bullet #2)
But you could tell users to run your app as admin.
The user can choose to run your app as admin by right click your app and choose more and you could find the option as Run as Administartor
Best regards,
Currently, UWP apps don't have the option to Run as administrator.
Another thing that needs to say is that with the 1809 update for Windows 10, desktop bridge apps can now declare a new capability -allowElevation in order to require elevation.

What is the best way to keep a C# Console app running [duplicate]

This question already has answers here:
How to keep a .NET console app running?
(9 answers)
Closed 6 years ago.
I have developed a console app which must run in the background. The app must constantly check a database for new records. If new records are returned they are processed. My app as it currently stands uses while(true) to keep the application running. Is using a while loop the best solution.
A snippet of my code:
static void Main(string[] args)
{
while(true)
{
// Query db for new records
if(record_count > 0)
{
// Process the records
}
Thread.Sleep(500);
}
}
Create as Windows Service Application
What a Windows Service is ?
Enables you to create long-running executable applications that run in their own windows session.
Can be automatically started when the computer boots, can be paused and restarted without any user interaction.
Easily installable by running the command line utility InstallUtil.exe and passing the path to the service's executable file.
Why a Windows Service?
One of the most common requirements of some businesses is long-running scheduled jobs based on some time interval. For example: sending a newsletter everyday afternoon or send an email alert to the customer for every one hour.
So building a Windows Service could be one of the reliable solutions to do the goal that can do the required job in the behind the scenes without interfering others users on the same computer.
Please refer the link for step by step implementation -
http://www.c-sharpcorner.com/UploadFile/naresh.avari/develop-and-install-a-windows-service-in-C-Sharp/
Your approach to keep your console application continuously running is absolutely fine. Only thing is that you want to keep it running in background silently without user to know anything. Since a console app has a windowed UI (a command console) the user will keep seeing it. Here is what you can do to get rid of command console. Since you already have your console application with you, here is what you need to do :
Go to project properties -> Go to application Tab -> Change the Output type to Windows Application
Phew! Now your same console application will run without a command console and your code will keep running.
Creating a windows service will be too much of a kill for such a simple logic. Also installing a windows service is an extra overhead, though I am not aware of the deployment you are looking forward to for your application in production.
Better option would be to use Windows service that run in background.
Creating a Windows Service Application
Develop and Install a Windows Service in C#
Just google and you can find lots of article and tutorial on Windows Service.
There is no need to make your program running as a services. Services aren't for these small tasks. You should simply create a Windows (GUI, WinForms) application with a hidden window. Or, just don't create a window and just keep the Main running. Main would launch a thread and would itself wait for that thread.
A service has to be installed as a service and not all users would have permission to do that. It is complex task to have service, manage it, have security attributes settled et. al.
The hidden application can simply run in current user account (the service would be running in high-privilege SYSTEM or NETWORK account). Your application won't demand any privilege from current user - it just need SQL database/table read access.
Create a windows service which will check if your console app is running. If console app is down, then windows service will execute it again.
Don't write your console app's code into windows service. Because if it will start automatically at windows start up, then it may not work correctly as your console app.

Running an admin task from a windows service

I have a Windows Service from which I have to run a process. However, that process requires admin privileges to run. Inside Process Explorer, I see that the service does run the process but the UI for that process does not appear up.
What am I missing here? How can this be rectified?
The services run in a separate session, with a separate desktop. Think of it as if the services where running in another remote desktop session. Anything with a GUI that you start from within a service will be shown in that hidden session, which cannot be accessed.
If you're working on Windows Vista or 7, services can't interact with desktop like windows XP and they can't open a window like ordinary windows applications. They default run as Local System account which is a fully privileged account.

Running Windows Service in Foreground

I have a bat file which is installed as a service. I can run the service on a remote box. This service needs to launch another application. The launched application needs to be visible(run in foreground). Currently the launched application is running in background as the windows service is running in background. How can i make the windows service or both the windows service and the application that it launches run in foreground? I intend to manage the service with the ServiceController class in C#.
I think you should probably read
http://asprosys.blogspot.com.au/2009/03/allow-service-to-interact-with-desktop.html
Making a service to just launch another app is a real security issue, what if your other app gets replaced with something else do you have all the checks in your Service to ensure your app is the app you think it is.
A proper approach is to launch the second application in the user's session, while your Windows service app always runs in session 0.
The approach has been part of my discussion with #RaheelKhan under this thread,
How reliable is adding an application manifest to ensure elevated privileges across windows xp, vista and 7?
It requires proper understanding of Windows sessions, session isolation, and platform invoke.

Windows Phone 7 Scheduled tasks running

As i understand i can launch a PeriodicTask from my windows phone application. But will it be called after application is terminated? Or, most important, will it be called by system after device reboot (before user run the main app next time)?
Yeah, they will run after a reboot and when your application is terminated but Battery Save Mode can prevent execution.
Good introduction:
http://blogs.infosupport.com/blogs/alexb/archive/2011/05/26/multi-tasking-in-windows-phone-7-1.aspx

Categories