windows-services

How to remotely control a Windows Service with ServiceController?

元气小坏坏 提交于 2019-11-30 07:52:21
问题 I'm trying to control Windows Services that are installed in a remote computer. I'm using the ServiceController class. I have this: ServiceController svc = new ServiceController("MyWindowsService", "COMPUTER_NAME"); With this, I can get the status of the Windows Service like this: string status = svc.Status.ToString(); But I can't control the Windows Service (by doing svc.Start(); or svc.Stop(); ). I get the following exception: Cannot open Servicexxx service on computer 'COMPUTER_NAME' That

How can I send MailMessages using multiple threads?

梦想与她 提交于 2019-11-30 07:43:33
I hope you guys will bear with me for my total lack of direction in case of Threading. I have to implement a Mail Queue Processing System where I have to send emails queued up in a database through a Windows Service. It is not a producer-consumer pattern. I have fetched say 10 rows at a time into a datable. The datatable contains the serialized MailMessage object and SMTP sending details. If I have to use say a fixed number of threads (say 6 threads) Now how would I go about fetching a row from the datatable in a thread and then send the mail and again return to see if any more rows are

Office Interop Does Not Work in Windows Service

烂漫一生 提交于 2019-11-30 07:39:08
I have a very weird issue with Microsoft Office. I have a common library whose sole purpose is to open whatever word document file type is passed to it (by a full file path...) and save that opened word document as a pdf file. The weird issue is that if I consume that library from a windows service, whenever it attempts to open the word document, I get a null... aka, the word document never got opened. If however I consume the library from a WPF or Windows Form application I never have any issues. I am aware that there are issues with threading, (Single Thread Appartment) however I have no

How to debug a windows service using breakpoints?

余生长醉 提交于 2019-11-30 07:38:00
问题 I have a windows service with a timer. Its very hard to debug it. Because I start the service and put break points in different parts of the code. When I attach the process, I expect the service to start from the very beginning instead of some randome place in the middle code where I have break points. Its hard to debug like a normal application where you know the starting point. It appears that there are processes in the back ground that have not completed yet. So every single time, I start

Can you host multiple WCF processes in a single windows service?

筅森魡賤 提交于 2019-11-30 07:36:53
I have a WCF process hosted in a windows service. I am wondering if I can safely have multiple WCF processes that do different things hosted in the same windows service. Do I have to worry about ports? I am using a mex endpoint Yes, you can. I am doing this exact thing in my project, hosting three separate WCF services inside my Windows service. Just make sure that each WCF endpoint, i.e., the address/binding/contract tuple, is unique. EDIT: SO seems to be trimming my lengthy code/config example so there's a complete explanation here: http://thegrenade.blogspot.com/2009/08/hosting-multiple-wcf

How to deploy Windows Service projects with Team Build 2010

六眼飞鱼酱① 提交于 2019-11-30 07:18:08
I have a VS2010 solution, which includes several Windows Service projects. I need to deploy these services as part of a build in Team Build 2010, and the Windows Services have to be deployed on several Windows Server machines. How can I do this? You could conditionally invoke the SC.exe command from your Windows Service project file (*.csproj) to install the Windows Service on a remote machine. Here's an example: <PropertyGroup> <DeployWinService>false</DeployWinService> <WinServiceName>MyService</WinServiceName> <TargetWinServiceHost Condition="'$(TargetWinServiceHost)' == ''">localhost<

Check if a service exists on a particular machine without using exception handling

倖福魔咒の 提交于 2019-11-30 06:48:45
问题 Don't know if there is a better way to do this, so that is the reason for the question. I can check if a service exists on a particular machine with the following code: bool DoesServiceExist(string serviceName, string machineName) { ServiceController controller = null; try { controller = new ServiceController(serviceName, machineName); controller.Status; return true; } catch(InvalidOperationException) { return false; } finally { if (controller != null) { controller.Dispose(); } } } but this

How to make a Windows service with parameters?

随声附和 提交于 2019-11-30 06:47:55
I have written a Windows service, of which I want to have 1 instance running per customer. This is because the customers each have their own DB with identical schemas; the only difference between the Windows services is that they will each have a different parameter corresponding to the customer DB that they're designated to serve. (And I can't have one service with multiple worker threads, because the DB connection uses a static variable, which I can't fiddle with across threads.) I found this neat little tutorial about how to make a Windows Service, but it only shows me how to set it up for

Using InstallUtil to install a Windows service with startup parameters

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 06:38:13
问题 I am using InstallUtil to install my service and I just cannot figure out how to specify the startup parameters for it! Here is my Installer subclass: [RunInstaller(true)] public class ServerHostInstaller : Installer { private ServiceInstaller m_serviceInstaller; private ServiceProcessInstaller m_serviceProcessInstaller; private static string s_usage = "Usage:\ninstallutil /i /username=<user_name> /password=<user_password> NCStub.Server.Host.exe"; public ServerHostInstaller() { m

Windows Service vs Windows Application - Best Practice

好久不见. 提交于 2019-11-30 06:27:14
问题 When should I go for a Windows Service and when should I go for a "Background Application" that runs in the notification area? If I'm not wrong, my design decision would be, any app that needs to be running before the user logins to the computer should be a service. For everything else use a background app. Is my decision right? Moreover, if I need "admin privileges" for my background app, I would escalate using a manifest. Are there any other specific advantage of running as a service? 回答1: