windows-services

how to get phyiscal path of windows service using .net?

*爱你&永不变心* 提交于 2019-11-27 03:15:08
问题 I have to get the absolute path of a windows service in a .Net Admin application. I am using ServiceController of .Net as shown below. ServiceController serviceController = new ServiceController(serviceName); But I don't see any property here to get the absolute path of the .exe of the service. Is there anyway to get this programmatically. 回答1: You can get this using WMI, which requires an assembly reference to System.Management: using System.Management; class Program { static void Main

Install Windows Service with Recovery action to Restart

£可爱£侵袭症+ 提交于 2019-11-27 03:11:29
I'm installing a Windows Service using the ServiceProcessInstaller and ServiceInstaller classes. I've used the ServiceProcessInstaller to set the start type, name, etc. But how do I set the recovery action to Restart? I know I can do it manually after the service is installed by going to the Services management console and changing the settings on the recovery tab of the service's properties, but is there a way to do it during the install? You can set the recovery options using sc . The following will set the service to restart after a failure: sc failure [servicename] reset= 0 actions=

Console.WriteLine() inside a Windows Service?

六眼飞鱼酱① 提交于 2019-11-27 03:03:08
问题 I am currently using TopShelf with a Console Application to create a Windows Service. When I run the code as a console application I use a few Console.WriteLine() to output results. Once the code does what it is supposed to do I install the console application as a Windows Service. Are there any downsides with leaving the Console.WriteLine() code even though a Windows Service can not write to the console? Are there any risks of having unstable code if I leave the Console.WriteLine() in there?

Debug Windows Service

天大地大妈咪最大 提交于 2019-11-27 02:43:22
Scenario I've got a windows service written in C#. I've read all the google threads on how to debug it, but I still can't get it to work. I've run "PathTo.NetFramework\InstallUtil.exe C:\MyService.exe". It said the install was successful, however when I run "Services.msc", The service isn't displayed at all, anywhere. If I go into Task Manager, there is a process called "MyService.vshost.exe". Pretty sure that's not it, because it's a service, not a process. Can Someone Explain To Me? If I am supposed to see the service when I run Services.msc? (Bearing in mind this is all being done on a

Automatically start a Windows Service on install

妖精的绣舞 提交于 2019-11-27 02:37:26
I have a Windows Service which I install using the InstallUtil.exe. Even though I have set the Startup Method to Automatic, the service does not start when installed, I have to manually open the services and click start. Is there a way to start it either via the command line, or through the code of the Service? codemonkey In your Installer class, add a handler for the AfterInstall event. You can then call the ServiceController in the event handler to start the service. using System.ServiceProcess; public ServiceInstaller() { //... Installer code here this.AfterInstall += new

Play Framework 2 Stage Task on Windows, “The input line is too long”

别等时光非礼了梦想. 提交于 2019-11-27 02:34:46
问题 I'm trying to Play 2 application on Windows Server Server 2012 using the "stage" task, with the goal of wrapping this up in a service so the application will automatically run when the server gets restarted. However, when running the app I get the following message: The input line is too long. The syntax of the command is incorrect. This is because Windows has a limit of around 8000 characters for command line instructions but it seems like the Play stage command is exceeding this by passing

Always Running Threads on Windows Service

China☆狼群 提交于 2019-11-27 02:26:02
问题 I'm writing a Windows Service that will kick off multiple worker threads that will listen to Amazon SQS queues and process messages. There will be about 20 threads listening to 10 queues. The threads will have to be always running and that's why I'm leaning towards to actually using actual threads for the worker loops rather than threadpool threads. Here is a top level implementation. Windows service will kick off multiple worker threads and each will listen to it's queue and process messages

Can a service written in .NET self-terminate?

感情迁移 提交于 2019-11-27 02:13:26
问题 I have a service application written in C# and under certain circumstances, I would like it to terminate itself. This would happen after the service has been running for a while, so this would not be happening in the OnStart() event. Everything that I have read so far suggests that the only safe way to terminate a service is through the Service Control Manager. My service runs as Local Service and does not have the rights to start or stop services, so I can't access the SCM from the service

Windows service couldnt get screenshot in windows 7

半城伤御伤魂 提交于 2019-11-27 02:12:55
I have a windows service which gets the screenshots. But its creating only black screens. I know this happens because of session 0 isolation. I searched on internet and couldnt find any approved solution for this problem any working ideas will be really good. 1- Is there a way to change the session of a windows service and get the desktop screen of another user's session like session 1, session 2? 2- Is there a way to start a console application which runs in an another session other than session 0 from a windows service? Is there a way to change the session of a windows service and get the

Can't debug Java Windows Services with jhat, jps, jstack

六月ゝ 毕业季﹏ 提交于 2019-11-27 01:54:32
问题 I frequently showcase the jhat, jps, and jstack tool set to developers on Linux and Mac. However, a developer recently indicated that these are unusable in Windows if the Java app in question is running as a Windows Service. A Sun-filed bug says something very similar, but was closed due to inactivity. I have tested this out for myself, and indeed it appears true, though I can hardly believe it. Here is the setup: Tomcat or similar running as a Windows service with the "Log On As" == "Local