如何在远程服务器上安装 C# Windows 服务?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17699644/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 10:14:12  来源:igfitidea点击:

How to install a C# Windows Service on a remote server?

c#windows-services

提问by Rune Hansen

Hi I have developed a C# Windows Service in Visual Studio. I am able to install this service on my local machine and it works fine. Now I want to be able to install it on a remote server.

嗨,我在 Visual Studio 中开发了一个 C# Windows 服务。我能够在我的本地机器上安装这个服务并且它运行良好。现在我希望能够将它安装在远程服务器上

Can you tell me how to do this?

你能告诉我怎么做吗?

My service is just built on the Windows Service VS template, so it's all very simple.

我的服务只是建立在Windows Service VS模板之上,所以一切都很简单

I am not so geeky, so it would be useful with some tutorial, manual which I can understand.

我不是那么极客,所以它对一些我能理解的教程和手册很有用。

I am running VS 2010 Professional.

我正在运行 VS 2010 Professional。

采纳答案by rtpHarry

You need to have Remote Desktop access to the server.

您需要具有对服务器的远程桌面访问权限。

When you are in you can do it via the commandline using something like this:

当您进入时,您可以使用以下内容通过命令行执行此操作:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\installutil /LogToConsole=true C:\Path\To\Service.exe

Then you can manage it (start it, set it to auto start, stop it, restart it) by going to Start | Run and typing

然后您可以通过转到开始 | 来管理它(启动它,将其设置为自动启动,停止它,重新启动它)。运行并输入

services.msc

then press enter.

然后按回车键。

To uninstall it use:

要卸载它,请使用:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\installutil /u /LogToConsole=true C:\Path\To\Service.exe

But you will need to have stopped the service first.

但是您需要先停止该服务。

Note: There is probably a new util in newer .net releases - my notes are from a while ago when I built a 2.0 service. Look in C:\Windows\Microsoft.NET\Framework\for a version number that matches the .net you're developing in.

注意:在较新的 .net 版本中可能有一个新的实用程序 - 我的笔记来自不久前构建 2.0 服务时的笔记。查找C:\Windows\Microsoft.NET\Framework\与您正在开发的 .net 匹配的版本号。

回答by Akram Shahda

Use the SCcommand.

使用SC命令。

sc \remotecomputer create newservice binpath= C:\Windows\System32\Newserv.exe 
   start= auto obj= DOMAIN\username password= pwd