开始&从另一个 Windows 服务停止一个 Windows 服务 [英] Start & Stop a Windows Service from another Windows Service

查看:29
本文介绍了开始&从另一个 Windows 服务停止一个 Windows 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从同一台机器(Windows 7 或 Server 2008)上的另一个(主)控制一个 Windows 服务(从).它无法启动或停止服务.我需要做什么才能控制服务?主服务是用C#编写的

I need to control a Windows service (slave) from another one (master) on the same machine (Windows 7 or Server 2008). It's unable to either start or stop the service. What do I need to do to be control the service? The master service is written in C#

更新:主服务旨在成为一种看门狗 - 它监视到从属的 HTTP 连接,并在从属无响应(不返回任何 HTTP 数据)时重新启动从属.

UPDATE: The master service is meant to be a sort of watchdog - it monitors an HTTP connection to the slave and restarts the slave if the slave is non-responsive (not returning any HTTP data).

推荐答案

处理 Windows 服务的最佳方式是使用 System.ServiceProcess 命名空间.检查它:https://ourcodeworld.com/articles/read/363/how-to-start-stop-and-verify-if-a-service-exists-with-c-in-winforms

The best way to handle windows services is to use System.ServiceProcess namespace. Check it on: https://ourcodeworld.com/articles/read/363/how-to-start-stop-and-verify-if-a-service-exists-with-c-in-winforms

但是您尝试这样做会遇到一些问题,因为您需要管理员权限才能关闭其他服务,因此您可以通过以下链接来处理(出于调试目的,您可以以管理员身份打开 VS,一切都会正常进行):

But you will have some problems trying that because you will need administrator permissions to turn other services off, so you can handle that by following this link (for debug purposes you can open your VS as admin and everything will work):

如何强制我的 .NET应用程序以管理员身份运行?

这篇关于开始&从另一个 Windows 服务停止一个 Windows 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆