开发者

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

开发者 https://www.devze.com 2023-03-13 14:17 出处:网络
Currently I am developing desktop application that start/stop/restart windows services. public 开发者_Go百科static void StartService(string serviceName, int timeoutMilliseconds)

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

精彩评论

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

关注公众号