如何用VB.NET重启服务?

时间:2009-03-12 10:05:41

标签: vb.net

好的,所以我是VB.NET的新手并尝试编写一个程序,提示用户输入服务器名称,然后在该计算机上重新启动IIS。

问题1)未识别名称空间System.ServiceProcess 问题2)需要帮助代码,将servername传递给sub。

Imports System
Imports System.ServiceProcess
Imports System.IO
Imports System.Threading

Class RestartIIS
    Shared Sub Main()
        Run()
    End Sub

    Public Sub Run()
        Console.WriteLine("Please enter the Server Name: ")
        Dim ServerName As String = Console.ReadLine()

        Dim sc As ServiceController = New ServiceController("W3SVC")

        sc.Stop()
        Thread.Sleep(2000)
        sc.Start()

        Console.Write("Press Enter to Exit")
        Console.ReadLine()
    End Sub
End Class 

2 个答案:

答案 0 :(得分:2)

您应该通过右键单击项目并单击Add Reference ...来添加对System.ServiceProcess程序集的引用,并获取传递给Main方法的命令行参数,如下所示:

Imports System
Imports System.ServiceProcess
Imports System.IO
Imports System.Threading

Class RestartIIS
    Shared Sub Main(ByVal commandLineArgs() as String)
        Run(commandLineArgs(0))
    End Sub

    Public Sub Run(ByVal machineName as String)
        Console.WriteLine("Please enter the Server Name: ")
        Dim ServerName As String = Console.ReadLine()

        Dim sc As ServiceController = New ServiceController("W3SVC", machineName)

        sc.Stop()
        Thread.Sleep(2000)
        sc.Start()

        Console.Write("Press Enter to Exit")
        Console.ReadLine()
    End Sub
End Class

答案 1 :(得分:0)

init: function (series, options, x) {

var point = this,
    colors;
point.series = series;
point.color = series.color; // #3445
point.applyOptions(options, x);
point.pointAttr = {};

if (series.options.colorByPoint) {
    colors = series.options.colors || series.chart.options.colors;
    point.color = point.color || colors[series.colorCounter++];
    // loop back to zero
    if (series.colorCounter === colors.length) {
        series.colorCounter = 0;
    }
}

series.chart.pointCount++;
return point;