【问题标题】:How to create a service running a .exe file on Windows 2012 Server?如何在 Windows 2012 Server 上创建运行 .exe 文件的服务?
【发布时间】:2014-10-27 20:58:54
【问题描述】:

我在 .net 中创建了 .exe 并希望将其用作服务,在我的本地计算机上一直运行。我正在使用 windows server 2012。如何在我的本地计算机上设置服务。

**您可以使用 windows shell 脚本通过命令创建服务**

sc create 命令执行 CreateService API 函数的操作。

这是做什么...

  1. 将“yourapplication.exe”复制到计算机上的合适位置 Win2012 服务器(例如 C:\Windows\System32\ )。

  2. 使用“sc”创建启动“srvany”的新服务(例如 sc 创建“服务名称” binPath =“C:'Windows'System32'srvany.exe” DisplayName="我的自定义服务")

  3. 使用 RegEdit:为您的服务创建一个“参数”键(例如 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Servicename\Paramaters)

  4. 使用 RegEdit:在新创建的“参数”键中,创建 一个名为“Application”的字符串值并输入完整路径 您想要作为服务运行的应用程序。 (没有引号 必填。)

语法:-

sc [] 创建 [] [type= {own |分享 |内核 |文件系统 |录音 |交互类型= {拥有 |分享}}] [开始= {启动|系统 |汽车 |需求 |禁用}] [错误= {正常|严重 |关键 |忽略}] [binpath= ] [group= ] [tag= {yes |没有}] [依赖= ] [obj= { | }] [显示名称= ] [密码= ]

More...

【问题讨论】:

标签: windows service windows-server-2012


【解决方案1】:

您可以使用 PowerShell。

New-Service -Name "TestService" -BinaryPathName "C:\WINDOWS\System32\svchost.exe -k netsvcs"

参考 - https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-service?view=powershell-3.0

【讨论】:

  • 添加一个描述开关将使这个命令更有用。 New-Service -Name "TestService" -BinaryPathName "C:\WINDOWS\System32\svchost.exe -k netsvcs" -Description "Some Service Description"
【解决方案2】:

你也可以这样做,它似乎也很有效。 sc create "Servicename" binPath= "Path\To\your\App.exe" DisplayName= "My Custom Service"

您可以打开注册表并在服务的注册表项中添加一个名为 Description 的字符串,以添加更多关于它的描述性信息。它将显示在 services.msc 中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-24
    • 1970-01-01
    相关资源
    最近更新 更多