servicecontroller

Control a service on a remote server from IIS

不想你离开。 提交于 2020-01-06 02:54:06
问题 Please note: In each step I describe below I'm logged in as the same domain user account. I have a web application that controls a service on a remote machine (via ServiceController). When I connect to the website remotely and attempt to control the service, I get an InvalidOperationException: Access is denied. I know it CAN work, because when I connect to the website from the web server (remote desktop in, login as my domain user, then open the webpage), it works as expected. I have

How can I respond to a change in status for a Windows Service?

假装没事ソ 提交于 2019-12-22 10:59:56
问题 I wonder if there is any possible way to get or create an event for a status changed of a Windows Service. I know that the ServiceController class does not have the event, but it has the status. Is there any way that I can listen to an event? 回答1: This is exactly what the NotifyServiceStatusChange function is intended for. The docs say that it: Enables an application to receive notification when the specified service is created or deleted or when its status changes. I'm not sure if there's an

Starting a service in ASP.NET/C# with the right permissions

拈花ヽ惹草 提交于 2019-12-20 06:02:49
问题 on my website (written in ASP.NET/C#) I want the moderaters to be able to start a certain service. The code I have for this is: ServiceController svcController = new ServiceController("InvidualFileConversion"); if (svcController != null) { try { svcController.Stop(); svcController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(10)); svcController.Start(); } catch (Exception ex) { // error } } Now when I run this I get the error "Cannot open InvidualFileConversion service

Halt batch file until service stop is complete?

点点圈 提交于 2019-12-18 11:17:24
问题 I'm using a batch file to stop a Windows service. I'm using the sc command, but I'm open to other ideas, given the question below. The problem is that the batch file proceeds while the service is stopping (the stop argument to sc seems only to request the stop -- it doesn't wait for the stop). How can I modify the batch file to not proceed until the stop is complete ? 回答1: You can use NET stop , which is synchronous, i.e it will wait until the service stops. See - NET stop 回答2: sc stop

Change service credentials using ServiceController

倾然丶 夕夏残阳落幕 提交于 2019-12-11 14:54:03
问题 Is there a way to do this, but instead of using WMI which is not currently working in my environment, using ServiceController Class. using (ManagementObject service = new ManagementObject(new ManagementPath(objPath))) { object[] wmiParams = new object[11]; wmiParams[6] = _username; wmiParams[7] = _password; service.InvokeMethod("Change", wmiParams); Thread.Sleep(2000); //check if new credentials in order //Console.WriteLine("Service credentials changed"); } Thanks! 回答1: The ServiceController

best way to access a windows service via GUI

夙愿已清 提交于 2019-12-11 09:09:47
问题 I'm curious about the best way for a C# gui to access the functions of a Windows Service, be it WCF or ServiceController or some other option. I'll explain what I'm doing: on a regulated time interval the service will be zipping one hours worth of datafiles from location A and sending the zipped file to location B, this will be done in the background 24/7 or until the service is stopped by the user and runs even when no one is logged in (hence the need for service) I would like the user to be

How do do an async ServiceController.WaitForStatus?

£可爱£侵袭症+ 提交于 2019-12-07 06:44:46
问题 So ServiceController.WaitForStatus is a blocking call. How can it be done Task/Async manner? 回答1: The code for ServiceController.WaitForStatus is: public void WaitForStatus(ServiceControllerStatus desiredStatus, TimeSpan timeout) { DateTime utcNow = DateTime.UtcNow; this.Refresh(); while (this.Status != desiredStatus) { if (DateTime.UtcNow - utcNow > timeout) { throw new TimeoutException(Res.GetString("Timeout")); } Thread.Sleep(250); this.Refresh(); } } This can be converted to a task based

C# Query Windows Service

折月煮酒 提交于 2019-12-06 05:51:35
问题 I have been using an application that queries Windows Services running on remote servers and writes the Machine Name, Service Name, and Status to a database. However, I want to try and capture the startup type (Automatic, Manual, Disabled) as well. I was using a Service Controller which does not have any options for startup type so I started looking at using a Management Class. This class looks like it has everything I need but I don't know how to use it against my remotes servers. For the

How can I respond to a change in status for a Windows Service?

依然范特西╮ 提交于 2019-12-05 18:27:32
I wonder if there is any possible way to get or create an event for a status changed of a Windows Service. I know that the ServiceController class does not have the event, but it has the status. Is there any way that I can listen to an event? Cody Gray This is exactly what the NotifyServiceStatusChange function is intended for. The docs say that it: Enables an application to receive notification when the specified service is created or deleted or when its status changes. I'm not sure if there's an equivalent event wrapped in managed code, but this one is easy enough to get at using P/Invoke.

C# Query Windows Service

南笙酒味 提交于 2019-12-04 13:46:36
I have been using an application that queries Windows Services running on remote servers and writes the Machine Name, Service Name, and Status to a database. However, I want to try and capture the startup type (Automatic, Manual, Disabled) as well. I was using a Service Controller which does not have any options for startup type so I started looking at using a Management Class. This class looks like it has everything I need but I don't know how to use it against my remotes servers. For the Service Controller, I was doing this: ServiceController[] services = ServiceController.GetServices