简体   繁体   中英

Is it possible to install or update a Windows Service on a remote host in C#?

I am wondering if there's a Managed equivalent of functionality provided by CreateService () or ChangeServiceConfig () for Services on a remote host?

Service Installer class appears to only operate locally.

I would recommend looking at this existing question: Installing a windows service on a remote machine using a given username .

In this answer they mention using "SC.exe". This is a tool in windows that allows you to " create and start a service ". You should easily be able to run this program using the Process class in System.Diagnostics. For example here is code, based on the example by Patrick McDonald , that would start NewServ.exe on the computer "remotecomputer".

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");

If this doesn't work, then you should be able to create your own installer, copy it to the remote computer, and then start the process remotely. See this question for more details: How to execute a process on a remote machine, in c#

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM