Restart Windows service when not respond - windows

A legacy Service that I work is freezing due to database issues. And I'm looking for a simpler solution than fixing it.
In Aplication Form Version (Delphi), Windows recognize and show message that application is not responding.
Can Windows recognize when a service is not responding and restart the service?
In Service Properties the Recovery is only for failures.

In Aplication Form Version (Delphi), Windows recognize and show message that application is not responding.
Only if the main UI thread is blocked, but you shouldn't ever do anything in the main UI thread that can block it. Bad code design.
Can Windows recognize when a service is not responding and restart the service?
Not automatically, no. You need to fix your database code so it doesn't freeze up anymore in the first place. If that is not an option (which I highly doubt) then you will have to write a separate watchdog thread/process to monitor your code/service and kill it if it freezes up. If you kill the entire service, then Windows failure actions can be used to restart it.

Related

How does Windows Installer close an application during uninstall?

When uninstalling my application, it attempts to stop it if it's running:
Sadly, the automatically closing doesn't really work and it displays this error:
My applications disappear, the windows, the tray bar icon, they are all gone. But I can still see them in the process list.
I'm guessing Windows sends a signal to the applications to exit gracefully and the UI does so, but there's some lingering thread preventing the processes from terminating.
How does Windows Installer close an application during uninstall?
Once I know this I want to simulate it while debugging my app to see what's going on. Is this a sound plan?
Since Windows Vista, Windows Installer will leverage the Restart Manager to identify, close, and restart applications. Microsoft's documentation on Using Restart Manager, and in particular Using Restart Manager with a Primary Installer should be a solid starting point for implementing a test harness. Your applications and services should instead follow the Guidelines for Applications and Services.
The Guidelines for Applications discuss the messages sent to your application by the restart manager; services are restarted through the service control manager. In theory you could simulate the restart manager at that level, but I suspect you'd be better served by invoking the real thing, registering a carefully chosen list of resources to target just your application, if possible.

Debugging Windows Services while starting

How can I debug an windows service when it is starting?
I have an windows service that is falling to start and I add all the logs that I could but something is happening behind the scenes (between the installed service and Windows) that I cannot see (as far as my knowledge go).
I am not looking for code debugging here but windows message between the service and Windows, but I can't find any in event log, maybe I need to turn it on?
I am thinking that something between the lines of windows think my service is a virus, or windows is not been able to connect to my service by name, something like that.
Does anyone know how I can see this kind of information on Event Viewer or similar?
Debugging of Windows services is quite challenging as they are running in session 0 with no desktop and user interaction possible.
One way to debug your service is to setup a remote debugging session with windbg as described here.
Another way is to use my winsvcdiag tool which should make the process simpler and possible to debug from VS: https://lowleveldesign.wordpress.com/2015/06/22/how-to-debug-windows-services-written-in-net-part-ii/
And I'm not sure what type of event logs you want to see. When a windows service is failing there is usually a brief message in the System log. You may always look if process monitor is reporting any errors for your service.

MSI: An Application is running during silent update

I have an application that was installed as MSI package, I have next version of application that I plan to install in silent mode by special program.
When application is running I catch an issue: not all components of application installed
immediately, some of them will be really ready only after reboot. And I get unstable application.
I can check - is application running and wait until it closed, but I can't check the situation when user click on shortcut during silent installation.
How I can avoid this? Can I lock application during installation?
I suggest implementing Restart Manager support. Vista or later will attempt to shut down your application via the Restart Manager, you can decide how to handle it within your application (prompt user, autosave, something else, etc).
You won't catch the situation where the user starts the application during update, but it will handle multi-user sessions more gracefully than your custom code will.

VS2010 Setup Project, Disable application/service re-start/shutdown warnings

I've been googeling this issue for quite some time now without any success. Basically what i've done is to create a VS2010 Setup Project, the project has a few Custom Actions that interacts with the Spooler Service through p/invokes, adding monitors, ports, printers yada yada.
Ofcourse to be able to do this the spooler service must be running, and also restarted at one point during the installation, however the msi file seems to be able to figure out that I'm working with the Spooler Service and sometimes hints the user/administrator to shutdown the spooler service before the installation starts, this will ofcourse fail the entire installation.
Is it in some way possible to disable these warnings?
Thanks in advance
If you are referring to the files in use dialog, there's not much you can do.
Usually you can avoid this dialog by stopping the process through a custom action, but you need the process running.

Need suggestion on replacing Windows Service by invisible WinForm Application

I need a background application to support my client application, which should always run on the client machine regardless of the main client application is running or not.
Windows Service was my first choice but problems I faced with Windows Service were: ease of control over windows service through main client application, release and installation of patches to the windows service and troubleshooting if windows service fails to run.
So, I started thinking for alternatives to the Windows Service and found that a Windows Forms application with NO visible forms can do it for me. This invisible app should start with system startup and keep running all the time, doing all the work that a Windows Service would do. But before I go deeper into the development, I want to explore the pros and cons of this approach.
Any suggestions/comments on this approach?
Your requirements are more suited for windows service. Main advantage with windows service is that it will start as soon as system comes up, irrespective of anybody is logged into system or not.
To sort out deployment issues, you build your business logic into separate assembly and call the necessary function withing windows service. This way you can deploy just the modified assembly.
Winform application with invisible form will not serve the purpose. HTH
That's not possible. User-mode applications must be started by a user, and will not continue to run when that user logs off. That's the purpose of the SessionEnding event: to allow you to shut down your app gracefully when the user logs off or the computer is shutting down. You can't just start something at system startup and keep it running all the time.
You need a Windows Service for that. But you should be aware that under Windows Vista and later, a service cannot interact directly with the user. They run in a separate process and are restricted from displaying their own UI. It's not clear from the question exactly what your needs are, but this is an important limitation of a Windows Service that is worth considering. A proper design really shouldn't require this, but there are apparently a lot of people to whom this new, more secure behavior is a real surprise. I explain this in more detail in related answers to this question and this other question.

Resources