How to Programatically Start IIS 6.0 SMTP Virtual Server?(如何编程启动IIS 6.0 SMTP虚拟服务器?)
问题描述
我想知道如何以编程方式重新启动IIS 6.0 SMTP服务器。 我设置的SMTP服务器偶尔会崩溃。我已经有几天没有注意到了,但到目前为止已经太晚了,什么都做不了。
我希望每隔30分钟左右设置一个计划任务,以测试SMTP服务器是否正在运行,如果没有运行,计划任务将自动启动它。
我已经找到一种方法来检查SMTP服务器是否已启动并正在运行,但我还不知道如何在进程崩溃时重新启动它。
此处发布:Testing SMTP server is running via C#
任何帮助都是绝妙的!
谢谢您。
我正在用C#开发控制台应用程序,以检查它是否正在运行,因此任何代码示例也会很棒。
推荐答案
AServiceController可以帮助您,因为它有启动和停止方法。请查看MSDN页面中的示例。
从ServiceControllerStatus Enumeration中提取的另一个样本几乎就是您需要的(只需替换服务名称)。
ServiceController sc = new ServiceController("Telnet");
Console.WriteLine("The Telnet service status is currently set to {0}",
sc.Status.ToString());
if ((sc.Status.Equals(ServiceControllerStatus.Stopped)) ||
(sc.Status.Equals(ServiceControllerStatus.StopPending)))
{
// Start the service if the current status is stopped.
Console.WriteLine("Starting the Telnet service...");
sc.Start();
}
else
{
// Stop the service if its status is not set to "Stopped".
Console.WriteLine("Stopping the Telnet service...");
sc.Stop();
}
// Refresh and display the current service status.
sc.Refresh();
Console.WriteLine("The Telnet service status is now set to {0}.",
sc.Status.ToString());
这篇关于如何编程启动IIS 6.0 SMTP虚拟服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何编程启动IIS 6.0 SMTP虚拟服务器?


基础教程推荐
- SSE 浮点算术是否可重现? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 XML 转换为通用列表 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01