开发者

How do I start/stop/restart a windows service on a remote machine using .net

Currently I am developing desktop application that start/stop/restart windows services.

    public 开发者_Go百科static void StartService(string serviceName, int timeoutMilliseconds)
    {
        ServiceController service = new ServiceController(serviceName);
        try
        {
            TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);

            service.Start();
            service.WaitForStatus(ServiceControllerStatus.Running, timeout);
        }
        catch
        {
            // ...
        }
    }

Now I want code to perform same action on remote system(other system on the same network).

Thanks.


You will need to instantiate the ServiceController with the overloaded constructor that accepts a machine name, like this:

ServiceController service = new ServiceController(serviceName, machineName);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜