windows-services

Killing EXCEL.exe Process from C# in a Windows Service

纵饮孤独 提交于 2019-11-28 23:49:43
I have a windows service that opens up an Excel spreadsheet via the Microsoft.Office.Interop.Excel.Application object. Application xlApp = new Application(); Workbook workbook = xlApp.Workbooks.Open(fileName, 2, false); ... ... workbook.Close(); xlApp.Quit(); I would like to kill the EXCEL.exe process that is left running after it is done working with the workbook. I've tried the following with no success... // This returns a processId of 0 IntPtr processId; GetWindowThreadProcessId(new IntPtr(xlApp.Hwnd), out processId); Process p = Process.GetProcessById(processId.ToInt32()); p.Kill();

Install java program as a windows service: Alternative to JavaService? [closed]

走远了吗. 提交于 2019-11-28 23:43:32
I'd like to install a Java application as a Windows service. I did so successfully a couple of years ago using this Java Service wrapper . Unfortunately, it seems like this tool is not in development anymore and thus no Windows 7 and 64 bit versions are available. I need to install my Java application on Windows 7 and XP machines. Does anyone know a good alternative? Edit: I need this for commercial use; the suggested Java Service Wrapper from Tanuki is too expensive. Some time ago I used the tanuki project and we were very happy with it. I believe is one of the most popular ones. There is

I want my C# Windows Service to automatically update itself

﹥>﹥吖頭↗ 提交于 2019-11-28 22:35:16
Is there a framework that can be used to enable a C# Windows Service to automatically check for a newer version and upgrade itself? I can certainly write code to accomplish this, but I am looking for a framework that has already been implemented and (most importantly) tested. [edit] Here is a link to a similar question with links to modern projects that help accomplish this: Auto-update library for .NET? stephbu The only way to unload types is to destroy the appdomain. To do this would require separation of your hosting layer from your executing service code - this is pretty complex. (sort of

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

ぃ、小莉子 提交于 2019-11-28 22:18:42
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 seems like an ineffecient solution to me (due to the exception handling). Is there a better way to check

Receiving MSMQ messages with Windows Service

时光毁灭记忆、已成空白 提交于 2019-11-28 22:09:49
I'm creating a Windows Service in C#. What is the best way to listen for messages?? How do I code this properly?? You don't listen. You configure MSMQ Activation to activate your component when messages arrive. The link has all the details you need, code and configuration. As previously stated, MSMQ Activation is probably the best way, if you can use that. Alternatively, here is code that I've used: var ts = new TimeSpan(0, 0, 10); MessageQueue q = GetQueue<T>(); while (true) { try { Message msg = q.Receive(ts); var t = (T)msg.Body; HandleMessage(t); } catch (MessageQueueException e) { // Test

Windows Service hosted WCF over HTTPS

青春壹個敷衍的年華 提交于 2019-11-28 21:19:42
I've created and configured an SSL certificate as per these instructions from MSDN. I'm getting the error message that this question lists, but am not sure how to map the accepted answer in that question to my App.config file. The content of the config file, and the service itself worked correctly over http, it's just over https that the problem is occuring. My App.config file is currently: <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <bindings> <wsHttpBinding> <binding name="TransportSecurity"> <security mode="Transport"> <transport clientCredentialType="None"

Using InstallUtil to install a Windows service with startup parameters

╄→尐↘猪︶ㄣ 提交于 2019-11-28 20:46:31
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_serviceInstaller = new ServiceInstaller(); m_serviceInstaller.ServiceName = Program.ServiceName; m_serviceInstaller

Problem with testing a Windows service

删除回忆录丶 提交于 2019-11-28 20:23:51
问题 I want to make a Windows service that will access my database. My database is SQL Server 2005. Actually I am working on a website and my database is inside our server. I need to access my database every second and update the records. For that purpose I need to make a Windows service that will install into our server and perform the task. I have been accessing the database from my local machine and then running the service, but problem is I'm not sure how I can test this service. I tried to

How to properly stop a multi-threaded .NET windows service?

人盡茶涼 提交于 2019-11-28 19:54:14
问题 I have a windows service written in C# that creates a truck load of threads and makes many network connections (WMI, SNMP, simple TCP, http). When attempting to stop the windows service using the Services MSC snap-in, the call to stop the service returns relatively quickly but the process continues to run for about 30 seconds or so. The primary question is what could be the reason that it is taking 30+ seconds to stop. What can I look for and how do I go about looking for it? The secondary

How to write c# service that I can also run as a winforms program?

二次信任 提交于 2019-11-28 19:54:06
I have a windows service written in C# that acts as a proxy for a bunch of network devices to the back end database. For testing and also to add a simulation layer to test the back end I would like to have a GUI for the test operator to be able run the simulation. Also for a striped down version to send out as a demo. The GUI and service do not have to run at the same time. What is the best way to achieve this duel operation? Edit: Here is my solution combing stuff from this question , Am I Running as a Service and Install a .NET windows service without InstallUtil.exe using this excellent