windows-services

How to get windows service name from app.config

假如想象 提交于 2019-11-27 07:51:34
问题 i have a app.config <appSettings> <add key="ServiceName" value="HasService"/> <add key="ServiceDisplayName" value="HasService"/> </appSettings> my service installer class [RunInstaller(true)] public class MyServiceInstaller : System.Configuration.Install.Installer { public MyServiceInstaller() { var process = new ServiceProcessInstaller {Account = ServiceAccount.LocalSystem}; var serviceAdmin = new ServiceInstaller { StartType = ServiceStartMode.Manual, ServiceName = "HasService", DisplayName

Screenshot of process under Windows Service

送分小仙女□ 提交于 2019-11-27 07:50:50
问题 We have to run a process from a windows service and get a screenshot from it. We tried the BitBlt and PrintWindow Win32 calls, but both give blank (black) bitmaps. If we run our code from a normal user process, it works just fine. Is this something that is even possible? Or could there be another method to try? Things we tried: Windows service running as Local System, runs process as Local System -> screenshot fails Windows service running as Administrator, runs process as Administrator ->

How can I restart a windows service programmatically in .NET

拜拜、爱过 提交于 2019-11-27 07:31:56
How can I restart a windows service programmatically in .NET? Also, I need to do an operation when the service restart is completed. Frederik Gheysels Take a look at the ServiceController class. To perform the operation that needs to be done when the service is restarted, I guess you should do that in the Service yourself (if it is your own service). If you do not have access to the source of the service, then perhaps you can use the WaitForStatus method of the ServiceController . This article uses the ServiceController class to write methods for Starting, Stopping, and Restarting Windows

Can I have multiple services hosted in a single windows executable

送分小仙女□ 提交于 2019-11-27 07:27:16
My question is essentially the same as the following one but the answer did not help me. .NET Windows Service - multiple services in one project Essentially, I have 3 services, lets say "Service1", "Service" and "Service3". ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new Service1("Service1"), new Service2("Service2"), new Service3("Service3") }; ServiceBase.Run(ServicesToRun); I also have installer classes with corresponding serviceInstaller.ServiceName = "ServiceX" for each of these services. When I use installutil, i do see all 3 services on the Service manager. However,

Use one windows service to execute jobs and two web applications to schedule jobs

谁都会走 提交于 2019-11-27 07:26:37
问题 I have one SQL Server database as the job store, two web applications that both can schedule jobs, and a Quartz.NET windows service to execute jobs. I want the two web applications to just schedule jobs, while the windows service just to execute jobs. Here comes the problem: If I create IScheduler instances in the two web applications and in the windows service, they will execute jobs at the same time, there can be conflicts. If I do not create IScheduler instances in the two web applications

How cancel shutdown from a windows service C#

半世苍凉 提交于 2019-11-27 07:24:34
问题 I have a windows service started (written in C# .net2.0). I want to detect when the computer shutdown/reboot and cancel it. After the cancel I want do some actions and restart windows. I have tried it, but it not working using Microsoft.Win32; partial class MyService: ServiceBase { protected override void OnStart(string[] args) { SystemEvents.SessionEnding += new SessionEndingEventHandler(OnSessionEnding); } private void OnSessionEnding(object sender, SessionEndingEventArgs e) { e.Cancel =

Global exception handler for windows services?

五迷三道 提交于 2019-11-27 07:16:32
Is there a way to globally handle exceptions for a Windows Service? Something similar to the following in Windows Forms applications: Application.ThreadException += new ThreadExceptionEventHandler(new ThreadExceptionHandler().ApplicationThreadException); Here is some pretty robust code we advise people to use when they're implementing http://exceptioneer.com in their Windows Applications. namespace YourNamespace { static class Program { [STAThread] static void Main() { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ThreadException += new System

How to make Windows Service start as “Automatic (Delayed Start)”

风流意气都作罢 提交于 2019-11-27 06:36:02
问题 Scenario: A WCF service running as a Windows Service. Account is "User". What is done: I have overridden the OnBeforeInstall in the projectinstaller to be able to set username and password from a config file. What I would be able to do: I'd like to be able to set the starttype as Automatic (Delayed Start) What I have tried: I put the following coderow in the overridden OnBeforeInstall serviceInstaller1.StartType = ServiceStartMode.Automatic + 1; Figured I would trick the ServiceStartMode enum

Error 1053: the service did not respond to the start or control request in a timely fashion

人盡茶涼 提交于 2019-11-27 06:26:52
I have recently inherited a couple of applications that run as windows services, and I am having problems providing a gui (accessible from a context menu in system tray) with both of them. The reason why we need a gui for a windows service is in order to be able to re-configure the behaviour of the windows service(s) without resorting to stopping/re-starting. My code works fine in debug mode, and I get the context menu come up, and everything behaves correctly etc. When I install the service via "installutil" using a named account (i.e., not Local System Account), the service runs fine, but

Debugging windows services

我是研究僧i 提交于 2019-11-27 06:26:07
问题 I have created a windows service and installed it manually. Later started the service from Services tool. Now I want to dubug the windows service application from Visual studio IDE. When I try to attach the process from Debug tab in the IDE, the windows service process is shown in the list, but it is not highlighted to be attached. Is there any other main process that I should attach to debug service application. Any relevant information posted is appreciated. Thanks. 回答1: This doesn't answer