简体   繁体   English

在Universal Windows App中启动和停止服务

[英]Service Start and stop in Universal Windows App

I found the following Links in MSDN to help me start and stop the window services. 我在MSDN中找到了以下链接来帮助我启动和停止窗口服务。 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. 为此,我需要System.ServiceProcess.dll dll。

Namespace : System.ServiceProcess Assembly : System.ServiceProcess (in System.ServiceProcess.dll) 命名空间 :System.ServiceProcess 程序集 :System.ServiceProcess(在System.ServiceProcess.dll中)

I am trying to add this from NUget and got the error. 我试图从NUget中添加它并得到错误。

Type Script command : Install-Package System.ServiceProcess.ServiceController -Pre 键入脚本命令: 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. Install-Package:System.ServiceProcess.ServiceController 4.1.0-beta-23516为UAP,Version = v10.0上的System.ServiceProcess.ServiceController提供了编译时参考程序集,但没有与win10-兼容的运行时程序集臂。 At line:1 char:1 + Install-Package System.ServiceProcess.ServiceController -Pre + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Install-Package], Exception + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand 在第1行:char:1 + Install-Package System.ServiceProcess.ServiceController -Pre + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + .PackageManagement.PowerShellCmdlets.InstallPackageCommand

This namespace System.ServiceProcess cannot be supported in uwp. uwp不支持此命名空间System.ServiceProcess We cannot find this .Net api in .NET for UWP apps . 我们无法在.NET中找到适用于UWP apps的 .Net api。

Also you can add this reference manually by download the package from System.ServiceProcess.ServiceController . 您也可以通过从System.ServiceProcess.ServiceController下载程序包来手动添加此引用。 But you will still receive error when you run the code. 但是,您在运行代码时仍然会收到错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM