如何在 Windows 2012 Server 上创建运行 .exe 文件的服务?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25642966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create a service running a .exe file on Windows 2012 Server?
提问by Pradeep atkari
I have created .exe in .net and want to use as a service, run all time on my local machine. I am using windows server 2012. how to setup a service on my local computer.
我已经在 .net 中创建了 .exe 并希望用作服务,一直在我的本地机器上运行。我正在使用 Windows Server 2012。如何在本地计算机上设置服务。
**You can use windows shell script for create service with commands **
**您可以使用 windows shell 脚本通过命令创建服务 **
The sc create command performs the operations of the CreateService API function.
sc create 命令执行 CreateService API 函数的操作。
Here's what to do ...
这是该怎么做...
copy the "yourapplication.exe " to a suitable location on your Win2012 server (e.g. C:\Windows\System32\ ).
Use "sc " to create a new service that launches "srvany " (e.g. sc create "Servicename" binPath= "C:'Windows'System32'srvany.exe" DisplayName= "My Custom Service" )
Using RegEdit : create a "Parameters " key for your service (e.g. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Servicename\Paramaters)
Using RegEdit : within the newly created "Parameters " key , create a string value called "Application " and enter the full path to the application you are wanting to run as a service. (No quotes required.)
将“yourapplication.exe”复制到 Win2012 服务器上的合适位置(例如 C:\Windows\System32\ )。
使用“sc”创建一个启动“srvany”的新服务(例如 sc create "Servicename" binPath="C:'Windows'System32'srvany.exe" DisplayName="My Custom Service" )
使用 RegEdit :为您的服务创建一个“参数”键(例如 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Servicename\Paramaters)
使用 RegEdit:在新创建的“Parameters”键中,创建一个名为“Application”的字符串值,并输入您想要作为服务运行的应用程序的完整路径。(不需要引号。)
Syntax:-
句法:-
sc [] create [] [type= {own | share | kernel | filesys | rec | interact type= {own | share}}] [start= {boot | system | auto | demand | disabled}] [error= {normal | severe | critical | ignore}] [binpath= ] [group= ] [tag= {yes | no}] [depend= ] [obj= { | }] [displayname= ] [password= ]
sc [] 创建 [] [type= {own | 分享 | 内核| 文件系统 | 记录 | 交互类型= {自己| 分享}}] [开始= {启动| 系统| 汽车 | 需求| 禁用}] [错误= {正常| 严重| 批判 | 忽略}] [binpath= ] [group= ] [tag= {yes | no}] [depend= ] [obj= { | }] [显示名称= ] [密码= ]
回答by Clovis Portron
You can just do that too, it seems to work well too.
sc create "Servicename" binPath= "Path\To\your\App.exe" DisplayName= "My Custom Service"
你也可以这样做,它似乎也很好用。
sc create "Servicename" binPath= "Path\To\your\App.exe" DisplayName= "My Custom Service"
You can open the registry and add a string named Description in your service's registry key to add a little more descriptive information about it. It will be shown in services.msc.
您可以打开注册表并在服务的注册表项中添加一个名为 Description 的字符串,以添加更多关于它的描述性信息。它将显示在 services.msc 中。
回答by Sajid Nadeem
You can use PowerShell.
您可以使用 PowerShell。
New-Service -Name "TestService" -BinaryPathName "C:\WINDOWS\System32\svchost.exe -k netsvcs"