Questions tagged [servicecontroller]
104 questions
4
votes
3 answers
Get service path from services.msc c#
I'm trying to get service executable path from services.msc
I wrote the next code:
var service = ServiceController.GetServices().Where(p => p.ServiceName.Equals("Service name", StringComparison.InvariantCultureIgnoreCase));
if…

Ofir
- 5,049
- 5
- 36
- 61
3
votes
2 answers
ExecuteCommand servicecontroller - cannot excecute command on service
I am using the service controller executecommand function, like so:
ServiceController serviceController = new ServiceController("a Service",
Environment.MachineName);
…

blade33
- 131
- 2
- 7
3
votes
2 answers
How can I respond to a change in status for a Windows Service?
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?

guyl
- 2,158
- 4
- 32
- 58
3
votes
1 answer
How can I detect when it is safe to upgrade my windows service?
I have a windows service that polls a database and will do things depending on the records it finds.
I want to set up Azure Devops to automatically deploy an upgrade to this service.
In order to deploy the upgrade I need to stop the service.
Is…

Kirsten
- 15,730
- 41
- 179
- 318
3
votes
1 answer
Does ServiceController.WaitForStatus set the status or just wait?
I'm using ServiceController.WaitForStatus for the first time to limit time wasted on trying to start services that won't start. My assumption is to use it like this:
var sc = new ServiceController(_monitoredService);
var seconds = _startWaitTimeout…

ProfK
- 49,207
- 121
- 399
- 775
3
votes
1 answer
C# service onCustomCommand with parameters?
I am currently trying to implement a service that runs a special command that does something with arguments passed, for example: file paths. I am using the cmd command:
sc control "ServiceName" 128
However, this command doesn't provide any way for…

adam laninster
- 33
- 5
3
votes
2 answers
Unable to start and stop service using ServiceController
I have the below methods to start and stop a service. I call this method from another Console application to debug since I've used the methods in a Class Library(DLL).
The application is started with administrative rights.
public void…

Jerry
- 67
- 1
- 7
2
votes
2 answers
Communicate with a Windows Service using ServiceController class
I have a windows services project consisting of two services, service1 and service2. How can we communicate between the two services? For example, how can we have have service2 started by service1? Can I use the ServiceController class to do…

Saeid
- 13,224
- 32
- 107
- 173
2
votes
2 answers
Windows service started with ServiceController throws "RPC Server not available" when performing WMI connection
I have a Windows service being installed with my installer, and then started with the use of ServiceController:
public static int StartService(string serviceName, int timeoutMilliseconds)
{
ServiceController service = new…

Avilan
- 608
- 2
- 6
- 23
2
votes
1 answer
The ContextMenu of a NotifyIcon is not updating instantly
I'm creating a tray icon application with a context menu with 3 items in it. The tray icon is to control a service running, so the user can quickly start or stop it. Depending on the service status, I want to disable the Start Button if the service…

Jonathan
- 685
- 1
- 10
- 30
2
votes
1 answer
Selecting specific printer by name VB
I've made a program that will run on startup asking the users to select their default printer. The code shows all installed printers in a ComboBox and the submit Button will set the Printer selected in the ComboBox as the default printer for that…

scotthannah
- 23
- 4
2
votes
1 answer
How to trigger failure in a windows service?
For every windows service you can define "recover policy" indicating what to do in case of a failure.
This works for when the service fail to start, but how can I trigger "failure" if the service started successfully but did something wrong while…

Ronen Ness
- 9,923
- 4
- 33
- 50
2
votes
1 answer
Access is denied when start/stop Windows Service with ASP
I wrote an ASP.NET Web Application that shows all installed services for our product. My application can retrieve the state of service (running, stopped,...).
Additionally, my application should be able to start a stopped service and stop a running…

Matthias Burger
- 5,549
- 7
- 49
- 94
2
votes
1 answer
Remotely install Windows service
How do I remotely install a Windows service using C#?
(I prefer not calling sc.exe / psexec / powershell remoting).
Thanks!
Yuval

Yuval Peled
- 4,988
- 8
- 30
- 36
2
votes
0 answers
How can I use a .NET Framework class in a .NET Standard project (System.ServiceProcess.ServiceController)
I am looking to use the System.ServiceProcess.ServiceController class in a .NET Standard 2.0 project. In order to do so I downloaded the Microsoft.Windows.Compatibility packet from NuGet, whic includes among other things ( I also tried to simply…

Nicolo Castro
- 195
- 1
- 3
- 8