1
votes

I found the following Links in MSDN to help me start and stop the window services. There is code snippet which tells it is possible to start and stop the service.

ServiceController sc = new ServiceController("Telnet");
if  ((sc.Status.Equals(ServiceControllerStatus.Stopped)) 
        ||  (sc.Status.Equals(ServiceControllerStatus.StopPending)))
{
     sc.Start();
}  
else
{
  sc.Stop();
}  
sc.Refresh();

for this i need the System.ServiceProcess.dll the dll.

Namespace: System.ServiceProcess Assembly: System.ServiceProcess (in System.ServiceProcess.dll)

I am trying to add this from NUget and got the error.

Type Script command : Install-Package System.ServiceProcess.ServiceController -Pre

Error Message :

Install-Package : System.ServiceProcess.ServiceController 4.1.0-beta-23516 provides a compile-time reference assembly for System.ServiceProcess.ServiceController on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-arm. At line:1 char:1 + Install-Package System.ServiceProcess.ServiceController -Pre + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Install-Package], Exception + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

1
Are you going to submit the app to the store or will it be side loaded for business use? - Neil Turner
It is going toe submit the app to the store. - Ajaya Nayak
In that case, the answer by @Sunteen applies - Services are not available in UWP, they're considered legacy. You should research BackgroundTasks - Neil Turner
@AjayaNayak any updates? If you have get the result could you please consider to mark the answer? - Sunteen Wu

1 Answers

2
votes

This namespace System.ServiceProcess cannot be supported in uwp. We cannot find this .Net api in .NET for UWP apps.

Also you can add this reference manually by download the package from System.ServiceProcess.ServiceController. But you will still receive error when you run the code.