How to register a service on a remote host with C#?

G

Guest

hi,

If we want to register a service on a reomte host with C++, we call API
OpenSCManager/CreateService to do the job. But with C#, how to do it? Are
there any relevant classes to help?

Thanks in advance
-Zhilin
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Not sure about the fact that the target machine is not the local host, but
you could check ServiceInstaller class (It's the one used for local
instalations ) IIRC I have never seeen properties like target machine, etc

In the worst case escenario you can simply P/invoke the same API you use
from C++
 
M

mabra

Hi !

Sorry, that's one of the faces of .Net ;-)
They do not think much about management ...

I would use System.Management. The Win32_Service class has a Start
method and - naturally - this works remotely.

May be, that helps.
Best regards,
Manfred
 
W

Willy Denoyette [MVP]

| Hi !
|
| Sorry, that's one of the faces of .Net ;-)
| They do not think much about management ...
|
| I would use System.Management. The Win32_Service class has a Start
| method and - naturally - this works remotely.
|

Not sure why you mean with "one of the faces of .NET", it provides at least
two ways to register a service, the first is by using the
System.ServiceProcess.ServiceInstaller class the second by using
System.Management and WMI's class Win32_Service. And if you want, you can
always shell-out the service management stuff to the sc.exe utility, which
is the prefered way (AFAIK) to manage windows services.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top