如何在Windows 2012 Server上创建运行.exe文件的服务?

Pra*_*ari 14 windows service windows-server-2012

我在.net中创建了.exe并希望用作服务,在我的本地计算机上运行.我正在使用Windows Server 2012.如何在我的本地计算机上设置服务.

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

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

这是做什么的......

  1. 将"yourapplication.exe"复制到Win2012服务器上的合适位置(例如C:\ Windows\System32 \).

  2. 使用"sc"创建一个启动"srvany"的新服务(例如sc create"Servicename"binPath ="C:'Windows'System32'srvany.exe"DisplayName ="My Custom Service")

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

  4. 使用RegEdit:在新创建的"Parameters"键中,创建一个名为"Application"的字符串值,并输入要作为服务运行的应用程序的完整路径.(不需要引号.)

句法:-

sc [] create [] [type = {own | 分享| 内核| filesys | rec | interaction type = {own | 分享}}] [start = {boot | 系统| 汽车| 需求| 已禁用}] [error = {normal | 严重| 关键| ignore}] [binpath =] [group =] [tag = {yes | no}] [depend =] [obj = {| }] [displayname =] [password =]

更多...

小智 12

你也可以这样做,它似乎也运作良好. sc create "Servicename" binPath= "Path\To\your\App.exe" DisplayName= "My Custom Service"

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


小智 6

您可以使用PowerShell。

New-Service -Name "TestService" -BinaryPathName "C:\WINDOWS\System32\svchost.exe -k netsvcs"
Run Code Online (Sandbox Code Playgroud)

请参阅-https: //docs.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/new-service?view= powershell- 3.0