【问题标题】:Is it possible to install or update a Windows Service on a remote host in C#?是否可以使用 C# 在远程主机上安装或更新 Windows 服务?
【发布时间】:2013-08-15 00:53:05
【问题描述】:

我想知道CreateService() 或ChangeServiceConfig() 是否为远程主机上的服务提供了托管等效功能?

Service Installer 类似乎只在本地运行。

【问题讨论】:

    标签: c# pinvoke


    【解决方案1】:

    我建议查看这个现有问题:Installing a windows service on a remote machine using a given username

    在这个答案中,他们提到使用“SC.exe”。这是 Windows 中的一个工具,可让您“create and start a service”。您应该能够使用 System.Diagnostics 中的 Process 类轻松运行此程序。例如,这里是基于Patrick McDonald 示例的代码,它将在计算机“远程计算机”上启动 NewServ.exe。

    Process process = new Process();
    process.Start(@"C:\Windows\System32\SC.exe", @"\\remotecomputer create newservice binpath= C:\Windows\System32\Newserv.exe start= auto obj= DOMAIN\username password= pwd");
    

    如果这不起作用,那么您应该能够创建自己的安装程序,将其复制到远程计算机,然后远程启动该过程。有关详细信息,请参阅此问题:How to execute a process on a remote machine, in c#

    【讨论】:

    • 我希望避免使用单独的命令行实用程序,但 sc.exe 非常擅长远程和本地操作。
    • 可以理解,但至少这是一个解决方案。如果你有机会,你能否将我的答案标记为正确,如果它解决了你的问题?谢谢。
    猜你喜欢
    • 2017-05-02
    • 1970-01-01
    • 2021-11-07
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 2011-03-19
    • 1970-01-01
    • 2016-11-18
    相关资源
    最近更新 更多