如何在没有安装Visual Studio的计算机上安装Windows服务?

28

我知道安装 Windows 服务的唯一方法是使用"Visual Studio 2008 命令提示符",那么在没有安装 Visual Studio 的机器上安装 Windows 服务的方法有哪些呢(假设已安装 .NET 版本为 2.X)?

12个回答

0

以管理员身份运行CMD

前往

C:\Windows\Microsoft.NET\Framework64\v4.0.30319>

执行以下操作:

安装程序:C:\Dev\Codebase..\Main\Source....\bin\Debug\.exe


0
我发现在使用.Net Core时,无法以编程方式实现这一点,除非您创建安装程序,但那样的话并不是程序自己在安装。
但是,通过使用System.Diagnostics.Process,可以使用此解决方法。创建一个调用您喜欢的sc.exe安装或卸载命令的新进程。
例如:
void Install ()
{
    if (Environment.UserInteractive)
    {
        using (var process = new Process())
        {
            process.StartInfo.FileName = "sc.exe";
            process.StartInfo.Arguments = "";
            process.StartInfo.Verb = "runas";
            process.OutputDataReceived += Process_OutputDataReceived;
            process.Start();
            process.WaitForExit();
            // use ServiceController from System.ServiceProcess to start, configure the service
        }

        Environment.Exit(0);
    }
    else
    {
        // We can't do this as a service...
        Environment.Exit(2);
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接